views:

172

answers:

3

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.

A: 

Is it really a problem to use System.Web? It's no different than tying it to System.Configuration, or System.IO. Any application can make use of it, whether it's "offline" or not.

I routinely tie my web apps to assemblies that are more classically though of as "winforms" assemblies, to get access to useful collection objects and such.

womp
My thinking was just that if I change to winforms it would just be more correct to not have it depend on an unrelated assembly. Granted it is somewhat trivial.
Graham
+5  A: 

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 :-)

Joel Martinez
This was going to be my next plan of attack, thank you for validating.
Graham
+1  A: 

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.

Craig Stuntz