Greetings
On all my controllers I recycle the same code that wraps my models and to accesses the service layer — and I’m tired for copy / pasting it into each controller:
private IProjectService _service;
public New()
{
_service = new ProjectService(new ModelValidation(this.ModelState));
}
public New(IProjectService service)
{
_service = service;
}
Is there someplace where I can place this where all my controllers access it?
You could put in a base controller class that all your other controllers inherit from:
Alternatively, you could read up on dependency injection and look at using an IOC container to inject these dependencies.