I'm writing an ASP.NET MVC 3 app and I'm finding myself writing this line rather often in my action methods:
var user = _session.Single<User>(u => u.UserName == User.Identity.Name);
(Obviously used in conjunction with the AuthorizeAttribute
)
There are other things that get repeated quite often but this one is the most prominent and I end up having 3 actions next to each other, each needing to retrieve the authorized user.
So this needs DRY-ing up:
Should I write an
ApplicationContoller
from which all other controller inherit and expose aUser
property there or should I add this to myIAdminService
and expose it as a method?Is an ApplicationController something to avoid or to embrace in ASP.NET MVC?