StructureMap 并将空参数传递给实例 [英] StructureMap and passing null parameter to instance

查看:34
本文介绍了StructureMap 并将空参数传递给实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中使用 StructureMap 创建一个实例,构造函数接受一个字符串.在配置中,我使用占位符作为参数.我正在尝试创建参数值为 null 的对象.当我从 ObjectFactory 取回对象时,参数的值等于占位符,而不是 null.

I am creating an instance with StructureMap in code, and the constructor takes in a string. In the configuration I use a placeholder for the parameter. I am trying to create the object with the parameter value of null. When I get the object back from the ObjectFactory the value of the parameter is equal to the placeholder, not null.

这是我对对象的配置:

<DefaultInstance PluginType="Blah.NDQA.Core.Data.IUserManagementRepository,Blah.NDQA.Core" PluggedType="Blah.NDQA.Data.MySql.MySqlUserManagementRepository,Blah.NDQA.Data" companyID="placeholder"/>

这是我创建它的方式:

IUserRightsRepository rightsRepo = ObjectFactory.With("companyID").EqualTo(null).GetInstance<IUserRightsRepository>();

在特定情况下 companyID = null 并且实例中的值等于placeholder".

in the particular case companyID = null and the value in the instance is equal to "placeholder".

有关如何实际创建具有 companyID = null 值而不是占位符值的对象的任何信息将不胜感激....

Any information on how I can actually create the object with the value of companyID = null instead of the placeholder value would be appreciated....

推荐答案

尝试:

ObjectFactory.With<string>(null).GetInstance<IUserRightsRepository>();

这篇关于StructureMap 并将空参数传递给实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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