我一直在阅读有关构造函数过度注入的问题。
很明显这是SRP没有正确遵循的信号等。(顺便说一下,我正在使用Ninject!)
然而,在我的情况下,我很难理解如何解决这个问题。 最大的问题在于我的ViewModel中,我注入了DTO映射器和Repository以用于我的属性。
以下是我的视图模型构造函数的示例:
通用仓储(GenericRepository)位于Company.Product.DataAccess.Repositories中,映射器(mappers)位于Company.Product.Domain.Mappers中。
然而,在我的情况下,我很难理解如何解决这个问题。 最大的问题在于我的ViewModel中,我注入了DTO映射器和Repository以用于我的属性。
以下是我的视图模型构造函数的示例:
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);
}
我猜测我没有正确使用repositories/mappers,它们应该从viewmodel中移出...但我不确定具体在哪里或如何操作。这就是我的问题所在。
应用程序的架构如下:
Company.Product.Core
Company.Product.DataAccess
Company.Product.Domain
Company.Product.Presentation
通用仓储(GenericRepository)位于Company.Product.DataAccess.Repositories中,映射器(mappers)位于Company.Product.Domain.Mappers中。