Resolve dependency with autofac based on constructor parameter attribute

后端 未结 2 1651
甜味超标
甜味超标 2020-12-18 09:11

I\'m using Autofac. I want to inject a different implementation of a dependency based on an attribute I apply to the constructor parameter. For example:

clas         


        
2条回答
  •  时光取名叫无心
    2020-12-18 09:52

    Bryan's answer is good enough while you have several repositories and they have few constructor parameters. But it is difficult to set up your root when you have many of them. You can achieve this by scanning your class metadata on resolving an interface. When you get info about its parameters you can resolve actual implementation of it. See my answer here.

提交回复
热议问题