public class ServicesPrpvoder:IServicesPrpvoder 服务提供者
可以利用IserviceScoprFactory 创建一个 服务范围 IServiceScope对象
IServicesScope 的包含IServicesPrpvoder
任何一个 IServiceProvider都具有对跟容器的引用
源码
public interface IServiceScope : IDisposable
{
/// <summary>
/// The <see cref="System.IServiceProvider"/> used to resolve dependencies from the scope.
/// </summary>
IServiceProvider ServiceProvider { get; }
}
public interface IServiceScopeFactory
{
/// <summary>
/// Create an <see cref="Microsoft.Extensions.DependencyInjection.IServiceScope"/> which
/// contains an <see cref="System.IServiceProvider"/> used to resolve dependencies from a
/// newly created scope.
/// </summary>
/// <returns>
/// An <see cref="Microsoft.Extensions.DependencyInjection.IServiceScope"/> controlling the
/// lifetime of the scope. Once this is disposed, any scoped services that have been resolved
/// from the <see cref="Microsoft.Extensions.DependencyInjection.IServiceScope.ServiceProvider"/>
/// will also be disposed.
/// </returns>
IServiceScope CreateScope();
}
ServiceProviderServiceExtensions.cs
public static IServiceScope CreateScope(this IServiceProvider provider)
{
return provider.GetRequiredService<IServiceScopeFactory>().CreateScope();
}
标签:生命周期,服务,IServicesPrpvoder,IServiceScope,IServiceProvider,scope,CreateScope,IOC,p From: https://www.cnblogs.com/liujian1368928/p/16793261.html