如何使用 Unity 填充设置?
我的 web.config 文件中有以下 appSettings 键值:
<add key="SomeSettings.Received" value="Mottatt"/>
<add key="SomeSettings.Processing" value="Under behandling"/>
<add key="SomeSettings.Finished" value="Ferdig behandlet"/>
我有以下类:
public class SomeSettings : IConfigurationSettings
{
public string Received { get; set; }
public string Processing { get; set; }
public string Finished { get; set; }
}
在 StructureMap 中,以下内容将填充 SomeSettings 类:
ForConcreteType<SomeSettings>().Configure
.EnrichWith(
(session, original) =>
session.GetInstance<ISettingsProvider>().PopulateSettings(original)
);
我可以使用 Unity 执行类似的操作,而无需在 web.config 文件中进行更改吗?如果是这样,怎么办?
I have the following appSettings key-values in a web.config file:
<add key="SomeSettings.Received" value="Mottatt"/>
<add key="SomeSettings.Processing" value="Under behandling"/>
<add key="SomeSettings.Finished" value="Ferdig behandlet"/>
I have the following class:
public class SomeSettings : IConfigurationSettings
{
public string Received { get; set; }
public string Processing { get; set; }
public string Finished { get; set; }
}
In StructureMap the following would populate the SomeSettings class:
ForConcreteType<SomeSettings>().Configure
.EnrichWith(
(session, original) =>
session.GetInstance<ISettingsProvider>().PopulateSettings(original)
);
Can I do something similar with Unity without having to make changes in the web.config file? If so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之:Unity没有这样的功能。
但是 codeplex 上的 TecX 项目 包含一些针对 Unity 的增强功能,允许您执行相同的操作。
In short: Unity does not have such a feature.
But the TecX project on codeplex contains some enhancements for Unity that allow you to do the same thing.