mirror of https://github.com/abpframework/abp
parent
8c2295b367
commit
f87002eee1
@ -1,52 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace Volo.Abp.AspNetCore.DependencyInjection;
|
||||
|
||||
[ExposeServices(
|
||||
typeof(IHybridServiceScopeFactory),
|
||||
typeof(HttpContextServiceScopeFactory)
|
||||
)]
|
||||
[Dependency(ReplaceServices = true)]
|
||||
public class HttpContextServiceScopeFactory : IHybridServiceScopeFactory, ITransientDependency
|
||||
{
|
||||
protected IHttpContextAccessor HttpContextAccessor { get; }
|
||||
|
||||
protected IServiceScopeFactory ServiceScopeFactory { get; }
|
||||
|
||||
public HttpContextServiceScopeFactory(
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IServiceScopeFactory serviceScopeFactory)
|
||||
{
|
||||
HttpContextAccessor = httpContextAccessor;
|
||||
ServiceScopeFactory = serviceScopeFactory;
|
||||
}
|
||||
|
||||
public virtual IServiceScope CreateScope()
|
||||
{
|
||||
var httpContext = HttpContextAccessor.HttpContext;
|
||||
if (httpContext == null)
|
||||
{
|
||||
return ServiceScopeFactory.CreateScope();
|
||||
}
|
||||
|
||||
return new NonDisposedHttpContextServiceScope(httpContext.RequestServices);
|
||||
}
|
||||
|
||||
protected class NonDisposedHttpContextServiceScope : IServiceScope
|
||||
{
|
||||
public IServiceProvider ServiceProvider { get; }
|
||||
|
||||
public NonDisposedHttpContextServiceScope(IServiceProvider serviceProvider)
|
||||
{
|
||||
ServiceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Volo.Abp.DependencyInjection;
|
||||
|
||||
[ExposeServices(
|
||||
typeof(IHybridServiceScopeFactory),
|
||||
typeof(DefaultServiceScopeFactory)
|
||||
)]
|
||||
public class DefaultServiceScopeFactory : IHybridServiceScopeFactory, ITransientDependency
|
||||
{
|
||||
protected IServiceScopeFactory Factory { get; }
|
||||
|
||||
public DefaultServiceScopeFactory(IServiceScopeFactory factory)
|
||||
{
|
||||
Factory = factory;
|
||||
}
|
||||
|
||||
public IServiceScope CreateScope()
|
||||
{
|
||||
return Factory.CreateScope();
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Volo.Abp.DependencyInjection;
|
||||
|
||||
public interface IHybridServiceScopeFactory : IServiceScopeFactory
|
||||
{
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue