[英]How to append injectionMembers after registration in UnityContainer?
Suppose I have code like this: 假设我有这样的代码:
container.RegisterType<IService, Implementation>(name, manager,
new InjectionConstructor(...));
Then I need to add InterceptionBehaviour to my registration, so it would be great if class ContainerRegistration have some method like AppendInjectionMembers(...)
. 然后,我需要将InterceptionBehaviour添加到我的注册中,因此,如果类ContainerRegistration具有类似
AppendInjectionMembers(...)
方法,那就AppendInjectionMembers(...)
。
So the question is: is it possible to append injectionMembers after registration? 所以问题是:注册后是否可以追加injectionMembers? And if so, how to do that?
如果是这样,该怎么做?
Thanks for all, I found the answer 谢谢大家,我找到了答案
container.Configure<InjectedMembers>().
ConfigureInjectionFor<Implementation>(new InterceptionBehavior());
Another way without using obsolete class InjectedMembers
: 不使用过时的类
InjectedMembers
另一种方法:
container.RegisterType(null, typeof(Implementation), new InterceptionBehavior());
Or even using generic version (thanks to Chris Tavares) : 甚至使用通用版本(感谢Chris Tavares):
container.RegisterType<Implementation>(new InterceptionBehavior());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.