Home > database >  How do I add the method AddStackExchangeRedisCache to IServiceCollection in C#?
How do I add the method AddStackExchangeRedisCache to IServiceCollection in C#?

Time:11-17

I have this startup.cs file that adds the different services to my application. One of the services I need to add is AddStackExchangeRedisCache but I am getting an error that says

"IServiceCollection does not contain a definition for AddStackExchangeRedisCache and no accessible extension method AddStackExchangeRedisCache accepting a first argument of type IServiceCollection could be found (are you missing a using directive or an asssembly reference?)?"

I have the following stack exchange redis refernce in my CSPROJ

    <PackageReference Include="StackExchange.Redis" Version="2.6.66" />

And the method where I am trying to add the service is as follows.

public void ConfigureServices(IServiceCollection services) {
    services.AddStackExchangeRedisCache(options =>
        {
           // some code here
        }
    }

CodePudding user response:

Install Microsoft.Extensions.Caching.StackExchangeRedis nuget package.

  • Related