I'm currently developing a web application which uses MVC3. the MVC3 project accesses our Application logic through a Service layer. The Service layer accesses the Database using repositories accessed via the UnitOfWork pattern.
I just installed StructureMap to take care of injecting my Services into the MVC3 project. An Example controller would look like this
public class AccountManagementController : Controller
{
IAccountService accountService;
public AccountManagementController(IAccountService accountService)
{
this.accountService = accountService;
}
Now, my problem is that my AccountService class needs to have the UnitOfWork injected when structure map creates it. Currently I handle this by having 2 controllers. One takes an interface, the other instantiates a concrete class.
public class AccountService : IAccountService, IDisposable
{
private IUnitOfWork unitOfWork;
internal AccountService(IUnitOfWork unitOfWork)
{
this.unitOfWork = unitOfWork;
}
public AccountService()
{
this.unitOfWork = new UnitOfWork();
}
This seems like code smell to me. Is there a more correct way to handle this?
Thanks, AFrieze