DI with Unity when multiple instances of the same type is needed

前端 未结 6 1642
忘了有多久
忘了有多久 2021-01-02 09:12

I need help with this. I\'m using Unity as my container and I want to inject two different instances of the same type into my constructor.

class Example
{
           


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 09:37

    Not everything has to be automatically wired by the container. You can register the Example class like this:

    container.Register(new InjectionFactory(c =>
    {
        var receive = new MessageQueue("receivePath");
        var send = new MessageQueue("sendPath");
        return new Example(receive, send);
    });
    

提交回复
热议问题