structuremap - two implementations of same interface

前端 未结 4 411
悲哀的现实
悲哀的现实 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:25

    Don't need to be complicated. Just simply register all the implementations of an interface.

     this.For().Use(); 
     this.For().Use();
    

    Then structuremap will automatically inject all implementation of the IMessageService interface into any constructor that has IEnumerable/list/array of an interface. Like below:

    private IEnumerator _current; 
    public SomeClass(IEnumerable features) {
        _current = features.GetEnumerator();
        } 
    

    Hope it helps

提交回复
热议问题