拥有以下服务构造函数
public class Service : IService
{
public Service(IOtherService service1, IAnotherOne service2, string arg)
{
}
}
Run Code Online (Sandbox Code Playgroud)
使用.NET Core IOC机制传递参数有哪些选择?
_serviceCollection.AddSingleton<IOtherService , OtherService>();
_serviceCollection.AddSingleton<IAnotherOne , AnotherOne>();
_serviceCollection.AddSingleton<IService>(x=>new Service( _serviceCollection.BuildServiceProvider().GetService<IOtherService>(), _serviceCollection.BuildServiceProvider().GetService<IAnotherOne >(), "" ));
Run Code Online (Sandbox Code Playgroud)
还有其他方法吗?
c# dependency-injection ioc-container .net-core asp.net-core