Change injected object at runtime

后端 未结 2 689
一整个雨季
一整个雨季 2020-12-09 12:40

I want to have multiples implementation of the IUserRepository each implementation will work with a database type either MongoDB or any SQL database. To do this I have ITena

2条回答
  •  抹茶落季
    2020-12-09 13:18

    You can try injecting a factory rather than the actual repository. The factory will be responsible for building the correct repository based on the current user identity.

    It might require a little more boiler plate code but it can achieve what you want. A little bit of inheritance might even make the controller code simpler.

提交回复
热议问题