The distributed session state storage injects the IDistributedCache instance by default. This means you should configure the SQL Server distributed cache as the default one if you would like to use that for session state.
For your own caching purposes, you could create a "wrapper interface" which specifically represents the Redis cache (such as IRedisCache), register it and inject that in your middleware/controllers/services. For example:
public interface IRedisDistributedCache : IDistributedCache
{
}
public void ConfigureServices(IServiceCollection services)
{
// Add Redis caching
services.AddDistributedRedisCache();
services.AddSingleton<IRedisDistributedCache, RedisCache>();
// Add SQL Server caching as the default cache mechanism
services.AddDistributedSqlServerCache();
}
public class FooController : Controller
{
private readonly IRedisDistributedCache _redisCache;
public FooController(IRedisDistributedCache redisCache)
{
_redisCache = redisCache;
}
}