I am using the Entity Framework/Repository-UnitOfWork/Service layer method on this ASP.NET MVC Application and it works great, but it seems a layer might be missing in order to keep the controllers thin.
Lets take for example a user authentication scenario:
1) The AuthenticationController
takes a IAuthenticationService
which in turn takes a IUnitOfWork
and IRepository<User>
(I am using generic repositories).
2) In the controller I want to make its only concern that the service authenticates the user:
if (userService.AuthenticateUser(model.userName, model.password)) {
FormsAuthentication.SetCookie(...);
return RedirectToAction(...);
}
return View(model);
Some will say this is too much logic in the controller right? So it seems as though we might need a Application Manager if you will:
if (appManager.AuthenticateUser(model.userName, model.password)) {
// Here the app manager calls the service???
return RedirectToAction(...);
}
I am trying to keep my domain services agnostic of the consuming application so I can use them on MVC, WinForms, Console, WPF, WCF, etc.
My service layers only return domain objects, I need a place to transform them into View Models, but I want to keep that out of the controllers.
Any input on this would be great!!