Accessing HttpContext and User Identity from data layer

前端 未结 6 1959
Happy的楠姐
Happy的楠姐 2021-02-15 11:08

I need to implement AddedBy/ChangedBy type fields on my Base Entity that all other entities inherit from ( Fluent Nhibernate ).

Accessing HttpContext.User.Identity

6条回答
  •  借酒劲吻你
    2021-02-15 11:31

    I have used a factory to get the correct repo with or without a "CurrentUser" since sometimes you need to know who the user is and sometimes you don't.

    //I have a current user that I got from the Identity
    var repo = RepoFactory.GetRepo(currentUserId);
    
    //I don't have a current user
    var repo = RepoFactory.GetRepo()
    

    This way you can pull the Identity from the HttpContext and pass only details you need to the repo.

提交回复
热议问题