Autofac Repository Pattern and Unit Of Work


Staff member
I have searched a little bit and I am confused.

<a href="" rel="nofollow">First Approach</a> uses a repository and a service for each entity with Autofac. Unit of work class does not have repositories. Therefore, you should create each repository instead of just creating one unit of work class in caller constructor.

OrderService(IUnitOfWork unitOfWork, IUserRepository userRepository,IOrderRepository orderRepository,IBalanceRepository balanceRepository)

<a href="" rel="nofollow">Second Approach</a> uses just a generic repository. It uses extension classes instead of using one repository for each entity. Unit of work class has generic repositories.Therefore, you can just create a unit of work class on caller class constructor.

OrderService(IUnitOfWork unitOfWork)

In this approach we use one generic class for repositories but we create a repository object for each entity. If this approach is fine how can I implement it with Autofac ?

<a href="" rel="nofollow">Third Approach</a> uses one generic repository and one object for generic repository with Autofac. It uses generic methods instead of generic class. But generic repository has unit of work class instead of opposite. Is this anti pattern ?

OrderService(IUnitOfWork unitOfWork,IGenericRepository repository)

Which approach should I use ?