c# - how to unit test asp.net core application with ...
stackoverflow.com › questions › 37724738how to unit test asp.net core application with constructor dependency injection. I have a asp.net core application that uses dependency injection defined in the startup.cs class of the application: public void ConfigureServices (IServiceCollection services) { services.AddDbContext<ApplicationDbContext> (options => options.UseSqlServer (Configuration ["Data:FotballConnection:DefaultConnection"])); // Repositories services.AddScoped<IUserRepository, UserRepository> (); services.
c# - Unit testing the dependency injection - Stack Overflow
stackoverflow.com › questions › 56521382Jun 10, 2019 · Unit testing the dependency injection. Here is my container initiator class, which the responsibility is to register the dependencies. public class ContainerInit { public static IContainer BuildContainer () { var conFac = new ContainerFactory (); var builder = new ContainerBuilder (); builder.Register (conFac).As<IContainerFactory> ().SingleInstance (); builder.Register (c=> new MainClass (conFac)).As<IMainClass> ().SingleInstance (); builder.Register (c=> new Database (conFac)).