Hi Tony,
First of all, Kudos for your excellent contribution to the community.
Wouldn't it be nice if we introduce RepositoryFactory Pattern and Inject only that in the UnitOfWork Constructor.
So instead of this
public NorthwindUnitOfWork(INorthwindSlimContext context,
ICustomerRepository customerRepository,
IOrderRepository orderRepository) :
base(context as DbContext)
{
_customerRepository = customerRepository;
_orderRepository = orderRepository;
}
Something like this
public NorthwindUnitOfWork(INorthwindSlimContext context,
IRepositoryFactory repositoryRepository) :
base(context as DbContext)
{
_repositoryRepository = repositoryRepository;
}
public ICustomerRepository CustomerRepository
{
get { return _repositoryRepository.GetRepository<ICustomerRepository>() ; }
}
public IOrderRepository OrderRepository
{
get { return _repositoryRepository.GetRepository<IOrderRepository>() ; }
}
public class RepositoryFactory : IRepositoryFactory
{
private readonly IContainer _container;
public RepositoryFactory(IContainer container)
{
_container = container;
}
public T GetRepository<T>()
{
return _container.GetInstance<T>();
}
}
in this way we can avoid injecting all the repositories from the constructor.
Hi Tony,
First of all, Kudos for your excellent contribution to the community.
Wouldn't it be nice if we introduce RepositoryFactory Pattern and Inject only that in the UnitOfWork Constructor.
So instead of this
Something like this
in this way we can avoid injecting all the repositories from the constructor.