How to reuse a repository for each request
I am trying to use dependency injection for a repository, which in Program.cs
is registered as a service. However the repository keeps getting reinstanciated each time the controller is called.
Dot Net 8 (MVC), Repository Dependency injection, reinstanciates each time controller is called
I am trying to use dependency injection for a repository, which in Program.cs
is registered as a service. However the repository keeps getting reinstanciated each time the controller is called.
Make sure that the controller has a parameterless public constructor. MVC
I have an existing MVC controller with a parameterized constructor and it works just fine until I tried to inject a new interface in the constructor. below is an example of the original code that works