请问如何在.net core中如何将同一个实例注入到2个不同的接口?也就是将下面的MemcachedClient同时注入到IMemcachedClient与IDistributedCache:services.Add(ServiceDescriptor.Singleton<IMemcachedClient, MemcachedClient>());services.Add(ServiceDescriptor.Singleton<IDistributedCache, MemcachedClient>());
1 回答
偶然的你
TA贡献1841条经验 获得超3个赞
services.addSingleton<MemcachedClient,MemcachedClient>();
services.addSingleton<IMemcachedClient,MemcachedClient>(sp=>sp.getservice<MemcachedClient>());
services.addSingleton<IDistributedCache,MemcachedClient>(sp=>sp.getservice<MemcachedClient>());
- 1 回答
- 0 关注
- 933 浏览
添加回答
举报
0/150
提交
取消