Skip to content

Commit

Permalink
接触Redis类对IConfigProvider的强依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Dec 5, 2024
1 parent ee9369d commit 3304684
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion NewLife.Redis/NewLife.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="11.0.2024.1201" />
<PackageReference Include="NewLife.Core" Version="11.1.2024.1205" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions NewLife.Redis/Redis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ public Redis(IServiceProvider provider, String name) : this()
var log = provider.GetService<ILog>();
if (log != null) Log = log;

var configProvider = provider.GetRequiredService<IConfigProvider>();
configProvider.Bind(this, true, name);
var config = provider.GetService<IConfigProvider>();
config ??= JsonConfigProvider.LoadAppSettings();
config.Bind(this, true, name);
}

/// <summary>实例化Redis,指定名称,支持从环境变量Redis_{Name}读取配置,或者逐个属性配置</summary>
Expand Down
8 changes: 4 additions & 4 deletions NewLife.Redis/Services/RedisCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void Init(IConfigProvider config, IServiceProvider? serviceProvider = nul

redis ??= new FullRedis(serviceProvider, "RedisCache")
{
Log = serviceProvider.GetRequiredService<ILog>(),
Tracer = serviceProvider.GetRequiredService<ITracer>(),
Log = serviceProvider.GetService<ILog>()!,
Tracer = serviceProvider.GetService<ITracer>(),
};
}
else
Expand All @@ -80,8 +80,8 @@ public void Init(IConfigProvider config, IServiceProvider? serviceProvider = nul

redis ??= new FullRedis(serviceProvider, "RedisQueue")
{
Log = serviceProvider.GetRequiredService<ILog>(),
Tracer = serviceProvider.GetRequiredService<ITracer>(),
Log = serviceProvider.GetService<ILog>()!,
Tracer = serviceProvider.GetService<ITracer>(),
};
}
else
Expand Down
2 changes: 1 addition & 1 deletion Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="11.0.2024.1201" />
<PackageReference Include="NewLife.Core" Version="11.1.2024.1205" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion XUnitTest/XUnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NewLife.Core" Version="11.0.2024.1201" />
<PackageReference Include="NewLife.Core" Version="11.1.2024.1205" />
<PackageReference Include="NewLife.UnitTest" Version="1.0.2024.1006" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down

0 comments on commit 3304684

Please sign in to comment.