相关疑难解决方法(0)

使用ASP.NET Core DI解析实例

如何使用ASP.NET Core MVC内置依赖注入框架手动解析类型?

设置容器很容易:

public void ConfigureServices(IServiceCollection services)
{
    // ...

    services.AddTransient<ISomeService, SomeConcreteService>();
}
Run Code Online (Sandbox Code Playgroud)

但是如何在ISomeService不进行注射的情况下解决?例如,我想这样做:

ISomeService service = services.Resolve<ISomeService>();
Run Code Online (Sandbox Code Playgroud)

没有这样的方法IServiceCollection.

c# dependency-injection asp.net-core-mvc asp.net-core

245
推荐指数
6
解决办法
17万
查看次数