传递参数的构造函数,初始化一个懒惰的实例时 [英] Pass parameters to constructor, when initializing a lazy instance

查看:158
本文介绍了传递参数的构造函数,初始化一个懒惰的实例时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我知道,如果一个变量被声明,那么当我们使用属性的构造函数被调用

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屋!

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