如何将Structuremap 3与对构造函数注入不友好的对象一起使用? [英] How do I use Structuremap 3 with objects that aren't friendly to constructor injection?

查看:94
本文介绍了如何将Structuremap 3与对构造函数注入不友好的对象一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从StructureMap 2.x迁移到3.x。一个主要变化是使用 ObjectFactory 会导致以下警告:

I'm moving from StructureMap 2.x to 3.x. One major change is that using ObjectFactory results in the following warning:


'StructureMap .ObjectFactory已过时: ObjectFactory
将在以后的StructureMap 4.0版本中删除。赞成将Container类的
用法用于将来的
工作'

'StructureMap.ObjectFactory' is obsolete: 'ObjectFactory will be removed in a future 4.0 release of StructureMap. Favor the usage of the Container class for future work'

因此,在大多数情况下,解决方案是相当容易:通过 IContainer 作为构造函数。不幸的是,这对于ASMX Web服务或属性都是不可行的,这两者都需要默认构造函数。这意味着我可能会被服务定位器模式,属性注入或编写我自己的ObjectFactory实现

So in most cases, the resolution is fairly easy: pass through IContainer as a constructor. Unfortunately this is not feasible for ASMX web serivces or attributes, both of which require a default constructor. That means I'm probably stuck with the Service Locator Pattern, property injection, or writing my own ObjectFactory implementation.

处理此不幸问题的首选方法是什么?

What's the preferred way to deal with this unfortunate problem?

编辑:值得一提的是,我的容器进行了装配

推荐答案

佩里(Jeremy Miller)本人


组装扫描并不便宜,您(几乎是? )总是要缓存
结果。所以,是的,在这种情况下,您将不得不编写自己的
ObjectFactory。有一天,所有那些糟糕的旧MS技术都将消失。

Assembly scanning isn’t cheap and you (almost?) always wanna cache the results. So, yeah, in that case you’re going to have to write your own ObjectFactory. Someday all that bad old MS tech will go away.

因此,在这种情况下,此实现是应该执行的操作。

So in this case, this implementation is what should be done.

这篇关于如何将Structuremap 3与对构造函数注入不友好的对象一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆