It is possible to register one type to multiple interfaces?
I have class that implement two interfaces
MyService : IService1, IServier2 {}
I would like to register this type for both interfaces.
container.RegisterType<IService1, MyService>(CreateLifetime());
container.RegisterType<IService2, MyService>(CreateLifetime());
Unfortunately during after resolving I have two different instances. I tried use common lifetime but then I got message that I can't.
I usually write this:
.RegisterType<MyService>(CreateLifeTime())
.RegisterType<IService1, MyService>()
.RegisterType<IService2, MyService>();
Of course with a TransientLifetimeManager, you still will get two different instances of MyService.
The code above works with PerResolveLifetimeManager, PerResolveLifetimeManager, PerThreadLifetimeManager.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With