[fix]降低RedisCacheProvider对IConfigProvider的依赖,在外部没有注册IConfigProvider时(常见于没有星尘),自动加载本地配置文件。
大石头 编写于 2024-10-31 09:19:20
NewLife.Redis
using System;
using Microsoft.Extensions.DependencyInjection;
using NewLife.Caching;
using Xunit;

namespace XUnitTest
{
    [Collection("Basic")]
    public class DependencyInjectionTest
    {
        public readonly ServiceProvider provider;

        public DependencyInjectionTest()
        {
            var services = new ServiceCollection();
            services.AddRedis("server=127.0.0.1;passowrd=;db=9");
            provider = services.BuildServiceProvider();
        }

        [Fact]
        public void SetAndGet()
        {
            var fullRedis = provider.GetService<FullRedis>();

            _ = fullRedis.Set<String>("test", "123456");

            var str = fullRedis.Get<String>("test");

            Assert.Equal("123456", str);
        }
    }
}