优化修复ShardingProvider的bug

This commit is contained in:
xuejiaming 2022-07-07 06:50:06 +08:00
parent eab96611fa
commit 3ca816b96d
3 changed files with 10 additions and 3 deletions

View File

@ -8,6 +8,7 @@ namespace ShardingCore.Core.ServiceProviders
/// </summary>
public interface IShardingProvider
{
void UseApplicationServiceProvider(IServiceProvider applicationServiceProvider);
/// <summary>
/// 优先通过ShardingCore的IServiceProvider获取
/// 没有再通过ApplicationServiceProvider获取

View File

@ -7,13 +7,19 @@ namespace ShardingCore.Core.ServiceProviders
public class ShardingProvider:IShardingProvider
{
private readonly IServiceProvider _internalServiceProvider;
private readonly IServiceProvider _applicationServiceProvider;
private IServiceProvider _applicationServiceProvider;
public ShardingProvider(IServiceProvider internalServiceProvider,IServiceProvider applicationServiceProvider)
{
_internalServiceProvider = internalServiceProvider;
_applicationServiceProvider = applicationServiceProvider;
}
public void UseApplicationServiceProvider(IServiceProvider applicationServiceProvider)
{
_applicationServiceProvider = applicationServiceProvider;
}
public object GetService(Type serviceType,bool tryApplicationServiceProvider=true)
{
var service = _internalServiceProvider?.GetService(serviceType);
@ -45,7 +51,7 @@ namespace ShardingCore.Core.ServiceProviders
public IShardingScope CreateScope()
{
return new ShardingScope(_internalServiceProvider.CreateScope(), _applicationServiceProvider.CreateScope());
return new ShardingScope(_internalServiceProvider.CreateScope(), _applicationServiceProvider?.CreateScope());
}
}

View File

@ -14,7 +14,7 @@ namespace ShardingCore.Core.ServiceProviders
_internalServiceScope = internalServiceScope;
_applicationServiceScope = applicationServiceScope;
_shardingProvider = new ShardingProvider(_internalServiceScope.ServiceProvider,
_applicationServiceScope.ServiceProvider);
_applicationServiceScope?.ServiceProvider);
}
public void Dispose()
{