I have some problems with constructors in controller
and service
that is called by controller
.
This is my service:
// model state dictionary for validation
private ModelStateDictionary _modelState;
// initialize UnitOfWork
private IUnitOfWork _unitOfWork;
public TownService(ModelStateDictionary modelState, IUnitOfWork unitOfWork)
{
_modelState = modelState;
_unitOfWork = unitOfWork;
}
Now in my controller I want to create new service, pass controller this.ModelState
but don't want to add UnitOfWork
inside controller.
Something like this:
private ITownService _townService;
public TownController()
{
_townService = new TownService(this.ModelState, null);
}
so that everything considering UnitOfWork
is done inside service. Controller just passes its own modelState
and service is one that creates new UnitOfWork
.
Is that possible and also good way? How can I achieve that? Or should I add new UnitOfWork
instead of null parameter in controller?
Because I want to separate Core, DAL, Web as much as possible so that everything does its part and with adding UnitOfWork in both controller and service seems like its not good way...
Thanks.