Can someone please guide me on how I can create instance of the below class that has ICacheManager Inject constructor. Since am new to this, not sure what type of parameter I have to pass when instantiating the below class to the constructor.
class RedisOperation : AbpModule
{
private readonly string CacheKey = "RedisPOC";
private readonly ICacheManager _cacheManager;
public RedisOperation()
{ }
public RedisOperation(ICacheManager cacheManager)
{
_cacheManager = cacheManager;
}
public async void SetValueInCache(string input)
{
var lstInputs = await _cacheManager.GetCache(CacheKey).GetOrDefaultAsync(CacheKey);
List<string> cacheInputStringList = new List<string>();
if(lstInputs != null)
cacheInputStringList = (List<string>)lstInputs;
cacheInputStringList.Add(input);
await _cacheManager.GetCache(CacheKey).SetAsync(CacheKey, cacheInputStringList);
}
public async void ClearCache()
{
var lstInputs = await _cacheManager.GetCache(CacheKey).GetOrDefaultAsync(CacheKey);
if (lstInputs != null)
await _cacheManager.GetCache(CacheKey).ClearAsync();
}
}
}
Now am trying to create instance of the above class, in main method as below,
static void Main(string[] args)
{
RedisOperation redisOp = new RedisOperation(); ==> Need to know how the ICacheManager object to be passed to the constructor to create the instance.
Console.WriteLine("Redis Cache POC");
Console.WriteLine("Choose below option to perform operation on RedisCache");
Console.WriteLine("1. Add");
Console.WriteLine("2. Clear");
var input = Console.ReadLine();
switch(int.Parse(input))
{
case 1:
string inputText = Console.ReadLine();
redisOp.SetValueInCache(inputText);
break;
case 2:
redisOp.ClearCache();
break;
}
}