IoC:创建 Unity 扩展来覆盖依赖项?
通过使用 Microsoft 的 Unity,我能够在解析实例时覆盖依赖项,例如:
var valueObjectThatOverridesAnyConfiguration = new object();
var container = new UnityContainer();
container.Resolve<ATypeWithConstructorArguments>(new DependencyOverride(typeof(object), valueObjectThatOverridesAnyPreviousConfiguration);
这将覆盖 UnityContainer 上的任何先前配置,并注入我在 DependencyOverride 上提供的实例。
有没有办法在容器级别中指定它?比如扩展什么的?我不想在下定决心的时候这么做!
谢谢!如果我让您感到困惑,请告诉我,我会提供更多信息。
By using Microsoft's Unity, I am able to override a dependency in the exact moment that I'm resolving an instance, for example:
var valueObjectThatOverridesAnyConfiguration = new object();
var container = new UnityContainer();
container.Resolve<ATypeWithConstructorArguments>(new DependencyOverride(typeof(object), valueObjectThatOverridesAnyPreviousConfiguration);
That will override any previous configuration on my UnityContainer and inject the instance I provided on the DependencyOverride.
Is there a way to specify it in a Container level ? Like an extension or something ? I don't want to do it at the resolve moment!
Thanks! Let me know if I'm being confuse to you, I'll provide more info.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的意思是像这个这样的东西吗?听起来像你的问题的部分是从线程的中间开始的。
它允许您执行此操作
可以在 TecX.Unity 项目中的此处找到源代码。
Do you mean something like this. The part that sounds like your problem starts in the middle of the thread.
It allows you to do this
The sources can be found here inside the TecX.Unity project.