Register multiple singletons with same interface but different constructor parameters

前端 未结 2 2016
无人及你
无人及你 2021-01-15 05:00

I have 2 storage (Azure) accounts lets call them src and dest and I have controllers that require access to both and I\'m trying to work out how to register these 2 singleto

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-15 05:34

    I would suggest defining two new interfaces:

    public interface IBlobAccessClientSource : IBlobAccessClient
    { }
    
    public interface IBlobAccessClientDestination : IBlobAccessClient
    { }
    

    And then registering them both individually (in whatever way that SimpleInject supports).

    Then in your consumers, inject in IBlobAccessClientSource and / or IBlobAccessClientDestination as needed. This will ensure that there are two singleton registrations - one for each of the two interfaces.

提交回复
热议问题