.NET Core IServiceScopeFactory.CreateScope() vs IServiceProvider.CreateScope() extension

后端 未结 1 580
执笔经年
执笔经年 2020-12-29 01:22

My understanding is that when using the built in the dependency injection, a .NET Core console app will require you to create and manage all scopes yourself whereas a ASP.NE

相关标签:
1条回答
  • 2020-12-29 01:38

    CreateScope from IServiceProvider resolve IServiceScopeFactory and call CreateScope() on it:

    public static IServiceScope CreateScope(this IServiceProvider provider)
    {
        return provider.GetRequiredService<IServiceScopeFactory>().CreateScope();
    }
    

    So, as said @Evk

    functionally both methods are identical

    IServiceProvider just wrapped call CreateScope() from IServiceScopeFactory

    0 讨论(0)
提交回复
热议问题