public class MemCachedHelper : ICacheHelper
{ private IMemcachedClient memcachedClient; public MemCachedHelper(IMemcachedClient memcachedClient)
{ this.memcachedClient = memcachedClient;
} public object Get(string key)
{ return memcachedClient.Get(key);
} public void Set(string key, object obj)
{
memcachedClient.Set(key, obj, int.MaxValue);
} public void Set(string key, object obj, int seconds)
{
memcachedClient.Set(key, obj, seconds);
} public void Remove(string key)
{
memcachedClient.Remove(key);
} public void RemoveAllCache()
{
memcachedClient.FlushAll();
}
}放在類庫項目中。那這個MemCachedHelper要如何使用?參數(shù)是?MemCachedHelper cache= new MemCachedHelper (????);
1 回答

慕工程0101907
TA貢獻(xiàn)1887條經(jīng)驗 獲得超5個贊
Startup 中注冊到依賴注入容器
public void ConfigureServices(IServiceCollection services){ services.AddTransient<MemCachedHelper>(); }
使用的地方通過構(gòu)造函數(shù)注入
public class UserService{ private readonly MemCachedHelper _memCachedHelper; public UserService(MemCachedHelper memCachedHelper) { _memCachedHelper = memCachedHelper; } }
- 1 回答
- 0 關(guān)注
- 793 瀏覽
添加回答
舉報
0/150
提交
取消