2

我有一个类当前需要一个IIndex以选择索引依赖项。我想将其更改为以某种方式使用构造函数参数上的属性,以便直接指定要使用的属性。

我很确定 Autofac 本身不支持这个,但我不害怕为此编写我自己的属性。我之前在 Autofac 的源代码端(自定义注册源等)搞砸了,但我从未见过定制注入端的方法。任何人都可以帮忙吗?

PS:我看过这个问题,但它变成了关于基于属性注入的好处的讨论。OTOH,我已经决定我不想手动注册每个依赖于这个特定依赖项的类型,所以我更喜欢它。

4

2 回答 2

2

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 the interface. See my answer here.

于 2013-09-28T12:56:40.387 回答
0

我注意到http://code.google.com/p/autofac/wiki/WebFormsIntegration说我们可以通过实现 IInjectionBehaviour 创建自定义依赖注入模型,我认为值得一试。

于 2013-01-15T02:58:56.687 回答