IServiceCollection override a single constructor argument

后端 未结 3 1922
执念已碎
执念已碎 2021-01-05 03:41

I have a class that takes three constructor arguments. In my composition root I want to define/override only one of the three constructor arguments; the oth

3条回答
  •  耶瑟儿~
    2021-01-05 04:11

    Try this:

    services.AddTransient();
    
    services.AddTransient();
    
    services.AddTransient(provider=>
        return new MyClass("constructor argument value",
          provider.GetService(),
          provider.GetService());
    );
    

提交回复
热议问题