优化修复ShardingProvider的bug
This commit is contained in:
parent
eab96611fa
commit
3ca816b96d
|
@ -8,6 +8,7 @@ namespace ShardingCore.Core.ServiceProviders
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IShardingProvider
|
public interface IShardingProvider
|
||||||
{
|
{
|
||||||
|
void UseApplicationServiceProvider(IServiceProvider applicationServiceProvider);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 优先通过ShardingCore的IServiceProvider获取
|
/// 优先通过ShardingCore的IServiceProvider获取
|
||||||
/// 没有再通过ApplicationServiceProvider获取
|
/// 没有再通过ApplicationServiceProvider获取
|
||||||
|
|
|
@ -7,13 +7,19 @@ namespace ShardingCore.Core.ServiceProviders
|
||||||
public class ShardingProvider:IShardingProvider
|
public class ShardingProvider:IShardingProvider
|
||||||
{
|
{
|
||||||
private readonly IServiceProvider _internalServiceProvider;
|
private readonly IServiceProvider _internalServiceProvider;
|
||||||
private readonly IServiceProvider _applicationServiceProvider;
|
private IServiceProvider _applicationServiceProvider;
|
||||||
|
|
||||||
public ShardingProvider(IServiceProvider internalServiceProvider,IServiceProvider applicationServiceProvider)
|
public ShardingProvider(IServiceProvider internalServiceProvider,IServiceProvider applicationServiceProvider)
|
||||||
{
|
{
|
||||||
_internalServiceProvider = internalServiceProvider;
|
_internalServiceProvider = internalServiceProvider;
|
||||||
_applicationServiceProvider = applicationServiceProvider;
|
_applicationServiceProvider = applicationServiceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UseApplicationServiceProvider(IServiceProvider applicationServiceProvider)
|
||||||
|
{
|
||||||
|
_applicationServiceProvider = applicationServiceProvider;
|
||||||
|
}
|
||||||
|
|
||||||
public object GetService(Type serviceType,bool tryApplicationServiceProvider=true)
|
public object GetService(Type serviceType,bool tryApplicationServiceProvider=true)
|
||||||
{
|
{
|
||||||
var service = _internalServiceProvider?.GetService(serviceType);
|
var service = _internalServiceProvider?.GetService(serviceType);
|
||||||
|
@ -45,7 +51,7 @@ namespace ShardingCore.Core.ServiceProviders
|
||||||
|
|
||||||
public IShardingScope CreateScope()
|
public IShardingScope CreateScope()
|
||||||
{
|
{
|
||||||
return new ShardingScope(_internalServiceProvider.CreateScope(), _applicationServiceProvider.CreateScope());
|
return new ShardingScope(_internalServiceProvider.CreateScope(), _applicationServiceProvider?.CreateScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace ShardingCore.Core.ServiceProviders
|
||||||
_internalServiceScope = internalServiceScope;
|
_internalServiceScope = internalServiceScope;
|
||||||
_applicationServiceScope = applicationServiceScope;
|
_applicationServiceScope = applicationServiceScope;
|
||||||
_shardingProvider = new ShardingProvider(_internalServiceScope.ServiceProvider,
|
_shardingProvider = new ShardingProvider(_internalServiceScope.ServiceProvider,
|
||||||
_applicationServiceScope.ServiceProvider);
|
_applicationServiceScope?.ServiceProvider);
|
||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue