Automatic ServiceCollection registrations by convention
We’ve now left the code in a non-functional state. This is because the built-in IoC container does not know how to resolve the IUsersService dependency and IUserDetailsService.
You need to explicitly tell ASP.NET which implementation it should use. Open your Program.cs file and put in the binding as follows:
var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); // Add these two lines to bind the services builder.Services.AddSingleton<IUsersService, UsersService>(); builder.Services.AddSingleton<IUserDetailsService, UserDetailsService>(); var app = builder.Build(); app.UseRouting(); app.UseEndpoints(_ => _.MapControllers()); app.Run();
The code adds a registration in the ASP.NET Core ServiceCollection for IUsersService to be resolved to UsersService, and it also explicitly says that it should add it as a singleton. This means that there will only...