I have ASP.Net Core 2.1
app. Need to use RedisCache
as Cache.
This is how my methods look to add an item to Cache.
public class RedisCache : ICache<Customer> //custom interface
{
#region Private
private readonly IConfiguration _configuration;
private readonly IDatabase _cache;
private readonly ConnectionMultiplexer _connection;
private readonly IRedisTypedClient<Customer> _redisClient;
#endregion Private
#region Ctor
public RedisCache(IConfiguration configuration, IRedisTypedClient<Customer> redisClient)
{
_configuration = configuration;
_connection = ConnectionMultiplexer.Connect(configuration.GetSection("AWS:Cache")["Redis:Server"]);
_cache = _connection.GetDatabase();
_redisClient = redisClient;
}
#endregion Ctor
public async Task<Customer> AddItem(Customer item)
{
try
{
await Task.Run(() => _redisClient.GetAndSetValue(item.Id, item)).ConfigureAwait(false);
return item;
}
catch (Exception ex)
{
Logger.Log(ex, item);
return null;
}
}
}
Dependency Registration
services.AddScoped<IRedisTypedClient<Customer>>(); //DI Registration
When the app runs, it throws the error
Unable to resolve service for type 'ServiceStack.Redis.Generic.IRedisTypedClient
So tried to register the DI as
services.AddScoped<IRedisTypedClient<Customer>>(di => new RedisTypedClient);
but nothing such found & compiler throws build error.
How to register this IRedisTypedClient
dependency?
Thanks!