请问如何在.net core中如何将同一个实例注入到2个不同的接口?也就是将下面的MemcachedClient同时注入到IMemcachedClient与IDistributedCache:
services.Add(ServiceDescriptor.Singleton<IMemcachedClient, MemcachedClient>());
services.Add(ServiceDescriptor.Singleton<IDistributedCache, MemcachedClient>());
services.addSingleton<MemcachedClient,MemcachedClient>();
services.addSingleton<IMemcachedClient,MemcachedClient>(sp=>sp.getservice<MemcachedClient>());
services.addSingleton<IDistributedCache,MemcachedClient>(sp=>sp.getservice<MemcachedClient>());
注入實例應該就可以了吧。
類似這樣。
services.AddSingleton<IOperationSingletonInstance>(new Operation(Guid.Empty));
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection