mirror of https://github.com/abpframework/abp.git
6 changed files with 68 additions and 12 deletions
@ -0,0 +1,12 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.DependencyInjection |
||||
|
{ |
||||
|
public class WebAssemblyClientScopeServiceProviderAccessor : |
||||
|
IClientScopeServiceProviderAccessor, |
||||
|
ISingletonDependency |
||||
|
{ |
||||
|
public IServiceProvider ServiceProvider { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using System; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.DependencyInjection |
||||
|
{ |
||||
|
public class HttpContextClientScopeServiceProviderAccessor : |
||||
|
IClientScopeServiceProviderAccessor, |
||||
|
ISingletonDependency |
||||
|
{ |
||||
|
public IServiceProvider ServiceProvider |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
var httpContext = _httpContextAccessor.HttpContext; |
||||
|
if (httpContext == null) |
||||
|
{ |
||||
|
throw new AbpException("HttpContextClientScopeServiceProviderAccessor should only be used in a web request scope!"); |
||||
|
} |
||||
|
|
||||
|
return httpContext.RequestServices; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private readonly IHttpContextAccessor _httpContextAccessor; |
||||
|
|
||||
|
public HttpContextClientScopeServiceProviderAccessor( |
||||
|
IHttpContextAccessor httpContextAccessor) |
||||
|
{ |
||||
|
_httpContextAccessor = httpContextAccessor; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.DependencyInjection |
||||
|
{ |
||||
|
public interface IClientScopeServiceProviderAccessor |
||||
|
{ |
||||
|
IServiceProvider ServiceProvider { get; } |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue