传递参数的构造函数,初始化一个懒惰的实例时 [英] Pass parameters to constructor, when initializing a lazy instance
问题描述
据我知道,如果一个变量被声明懒
,那么当我们使用值
属性的构造函数被调用
As I know if a variable is declared Lazy
, then its constructor is called when we use the Value
property.
我需要一些参数传递给该懒
实例,但找不到正确的语法。
这不是我的设计,我使用MEF和 ExportFactory
,它返回我懒
的实例我的部分。我的部分有构造函数和我需要调用这些构造一些参数。
I need to pass some parameters to this Lazy
instance but cannot find the correct syntax.
This is not my design, I'm using MEF and ExportFactory
, it returns me Lazy
instances of my parts. My parts have constructors and I need to call these constructors with some parameters.
推荐答案
MEF没有一个内置的方式为您传递构造函数参数的一部分,当你与ExportFactory创建它。像什么维姆·科嫩暗示的东西可能是实现你想要的最好的方法。
MEF doesn't have a built-in way for you to pass constructor parameters to a part when you create it with an ExportFactory. Something like what Wim Coenen suggests is probably the best way to achieve what you want.
这篇关于传递参数的构造函数,初始化一个懒惰的实例时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!