简体   繁体   English

在UnityContainer中注册后如何追加injectionMembers?

[英]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.

相关问题 如何将UnityContainer作为参数传递给Unity IOC xml配置文件中的注册 - How do I pass the UnityContainer as a parameter to a registration in a Unity IOC xml configuration file 如何在UnityContainer中常规设置LifeTimeManagement? - How to conventionally set the LifeTimeManagement in a UnityContainer? 如何使用UnityContainer Resolve进行调试? - How to debug using UnityContainer Resolve? 如何解析UnityContainer以及何时在Windows Serivce中 - How to resolve UnityContainer and when in windows serivce UnityContainer-如何通过依赖关系链进行注册/解析 - UnityContainer - how register/resolve with dependency chaining RegisterType()调用中的InjectionMembers是什么? - What are the InjectionMembers in RegisterType() calls for? 如何创建全局UnityContainer并在所有ViewModel中访问它? - How do I create a global UnityContainer and access it in all my ViewModels? 如何注册实现与UnityContainer相同接口的多个类? - How to register multiple classes that implements the same interface to UnityContainer? 如何结合PolicyInjection.Create和UnityContainer.RegisterType? - how to combine PolicyInjection.Create and UnityContainer.RegisterType? 如何设置UnityContainer.Resolve <IType> ()类型优先? - How set UnityContainer.Resolve<IType>() types precedence?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM