Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call asp.net Membership class from controller or service layer?

Should I access the asp.net membership class from the controller and pass the results to the service layer, or access it directly from the service layer?

I'm torn because on one hand this seems like business logic that should be handled in the service layer, but I don't want to tie the service layer to the web namespace as this might become an windows app down the road.

like image 501
Graham Conzett Avatar asked Aug 24 '09 20:08

Graham Conzett


2 Answers

the answer, use IoC to create a membership interface that the service layer uses. the website's implementation can use the web namespace. And the windows app can have a different implementation. and since you can inject that dependency, your service layer doesn't have to change :-)

like image 146
Joel Martinez Avatar answered Nov 15 '22 14:11

Joel Martinez


ASP.NET Membership is Web-specific, so that should be accessed in the Controller. MHO is that the service layer should not be hard-wired to the web. So for adding/removing users, do that via the Controller.

OTOH, in the service layer, you can read Thread.CurrentPrincipal.Identity, which is non-web-specific, but happens to be entirely compatible with ASP.NET Membership. So if you only need to get the current user you can do that without voilating separation of concerns.

like image 3
Craig Stuntz Avatar answered Nov 15 '22 13:11

Craig Stuntz