Injecting a Repository in a Controller
Learn how you can inject your repositories into your controller.
We'll cover the following...
Updating Startup.cs
To allow repository injection into your controllers, the ConfigureServices()
method inside Startup.cs
needs to be updated by adding the following two lines of code.
Press + to interact
// services.AddScoped<IUserRepo, MockUserRepo>();services.AddScoped<IUserRepo, SqlUserRepo>();
One of them is commented out so you can select and choose which repository you want to inject at a given time. If you want to inject the mock repository, you will remove the comment tag (//
) from the first line and ...