structuremap - two implementations of same interface

前端 未结 4 487
悲哀的现实
悲哀的现实 2021-02-02 01:14

I have a service class with the following ctor:

public class (IMessageService emailService, IMessageService smsService)
{ ... }

and two impleme

4条回答
  •  半阙折子戏
    2021-02-02 01:49

    //First just write below lines in IOC    
    
    this.For().Use();
    this.For().Use();
    
    
    //Then We can directly use it in our constructor injection of our class                             
    //Where we need it
    IEnumerable messageServices;  
    
    public ClassNeedsInjection(IEnumerable messageServices)                         
    {
        this.messageServices=messageServices;
        foreach (var messageService in this.messageServices)
        {
            //use both the objects as you wish
        }
    }
    

提交回复
热议问题