Register the same type to multiple interfaces

后端 未结 3 1666
天命终不由人
天命终不由人 2020-12-30 08:00

It is possible to register one type to multiple interfaces?

I have class that implement two interfaces

MyService : IService1, IServier2 {}

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 08:44

    I usually write this:

          .RegisterType(CreateLifeTime())
          .RegisterType()
          .RegisterType();
    

    Of course with a TransientLifetimeManager, you still will get two different instances of MyService.

    The code above works with PerResolveLifetimeManager, PerResolveLifetimeManager, PerThreadLifetimeManager.

提交回复
热议问题