I have been reading about the problem of constructor over-injection. It all makes sense that this is a sign where the SRP is not being followed correctly etc. (I am using Ninject by the way!)
However, I am having a hard time understanding how this can be solved in my case. The biggest problem is in my viewmodel where I am injecting DTO mappers and Repositories to be used with my properties.
Here is an example of what my viewmodel constructor could look like:
public MainViewModel(
IGenericRepository<MainDbContext, Product> productRepository,
IGenericRepository<MainDbContext, Person> personRepository,
IGenericRepository<MainDbContext, Order> orderRepository,
ProductMapper productMapper,
PersonMapper personMapper,
OrderMapper orderMapper,
IViewModelLoader viewModelLoader,
IEventAggregator eventAggregator)
{
_productRepository = productRepository;
_personRepository = personRepository;
_orderRepository = orderRepository;
_productMapper = productMapper;
_personMapper = personMapper;
_orderMapper = orderMapper;
_viewModelLoader = viewModelLoader;
_eventAggregator = eventAggregator;
_eventAggregator.Subscribe(this);
}
My guess is that I am not using the repositories/mappers correctly and they should be moved out of the viewmodel... I'm not sure exactly where or how. Which is the reason for my question.
The architecture of the application looks like this:
Company.Product.Core
Company.Product.DataAccess
Company.Product.Domain
Company.Product.Presentation
The GenericRepository is placed inside Company.Product.DataAccess.Repositories and mappers inside Company.Product.Domain.Mappers