netcore mvc reference constructor dependency injection with

public class DC_UserService: DBService<ApplicationUser>, IAdminService
    {
        public DC_UserService(ConnectionConfig config) : base(config)
        {
        }
}

Startup joins the code:

services.AddTransient<IAdminService>(x => new DC_UserService(DCConnectionConfig()));

Reference the following code (resolved):

public class Service : IService
{
     public Service(IOtherService service1, IAnotherOne service2, string arg)
     {

     }
}


_serviceCollection.AddSingleton<IService>(x => 
    new Service(x.GetRequiredService<IOtherService>(),
                x.GetRequiredService<IAnotherOne>(), 
                ""));

Reference source of the problem: https://stackoverflow.com/questions/53884417/net-core-di-ways-of-passing-parameters-to-constructor

Guess you like

Origin www.cnblogs.com/flames/p/11284528.html