IoC - Multiple implementations support for a single interface

后端 未结 7 1513
清歌不尽
清歌不尽 2020-12-30 02:50

I am wondering why .Net IoC containers do not easily support multiple implementations for a single interface! May be I am wrong, but as far I have seen, frameworks like Nin

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 03:06

    My container Griffin.Container supports it.

    registrar.RegisterConcrete();
    registrar.RegisterConcrete();
    

    And to fetch:

    var services = container.Resolve();
    

    However, you can't get one specific implementation. It's a design decision. It's much better to register a factory in the container if have to get a specific implementation. Read more here in the best practices section.

    Griffin.Container can be found at github: https://github.com/jgauffin/griffin.container

提交回复
热议问题