DbCommandInterceptor

问题描述

我正在尝试将Azure Redis缓存添加到我的应用程序。我正在尝试使用拦截器来执行此操作,因此当查询完成后,如果结果存在于缓存中,我将替换结果并减少一个查询,否则我将获得查询结果并将其存储在缓存中。 当然,只有在涉及某些表时,我才这样做。 我已将Redis缓存添加到我的启动中:

services.AddDistributedRedisCache(config =>
        {
            config.Configuration = GetAppSettingsValue("RedisConnectionString",Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"));
        });

现在我需要在拦截器中使用它

public class RedisCacheInterceptor : DbCommandInterceptor
{
    private readonly IDistributedCache _distributedCache;

    public RedisCacheInterceptor(IDistributedCache distributedCache)
    {
        _distributedCache = distributedCache;
    }
}

此时,当我尝试将拦截器添加到db连接时,我不知道如何使用依赖项注入来实例化拦截器。

我应该如何解决这个问题? 我是否以错误的方式使用拦截器?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)