Aokiri 🐸
Confusion about Repository Pattern and Unit of Work.
Hi there. I recently applied the Repository Pattern and Unit of Work in an API I'm creating, and everything was going well. However, I got stuck trying to understand how to pass the Database Context to the implementation of one of my interfaces. I'm trying to grasp it, but I can't figure it out. I'll attach few code for reference:
(Program.cs) Here is where I'll apply Dependency Injection for my ICategoryRepository with a Scoped lifetime:
(DataAccess/Repository/Repository.cs) Here is my implementation of my Repository Interface (only constructor and fields):
(DataAccess/Repository/CategoryRepository.cs) And here is my implementation of my Category Repository Interface (only constructor, as always):
Look how these two has inyected with the DbContext, but here comes my confusion...
In the controller, I created an ICategoryRepository object, but I don't understand how it pass the DbContext to the controller itself...
19 replies