Reputation: 35
I have an asp.net core project and I'm trying to use IDistributedCache
(Redis).
I want to access IDistributedCache
in a custom class, not only in a controller.
Is that possible?
Upvotes: 2
Views: 1536
Reputation: 246998
I want to access IDistributedCache in a custom class, not only in a controller. Is that possible?
Yes.
Register with service collection
var redisconnection = "...";
services.AddDistributedRedisCache(o => { o.Configuration = redisconnection; });
services.AddScoped<MyCustomClass>();
//...
and have it as an injectable argument on custom class
public MyCustomClass(IDistributedCache cache) {
//...
}
Upvotes: 2