StructureMap.配置自动设置
本文关键字:设置 配置 StructureMap | 更新日期: 2023-09-27 17:52:38
我有2个插件在我的应用程序(ASP。. NET MVC 4).它们都使用相同的接口。
例如MyApp.Plugins.Abstract.IMainPlugin
使用所需的Execute方法
现在,我有一个名为MyApp.Plugins.ClockPlugin
和MyApp.Plugins.TimePlugin
的插件。ClockPlugin类内部有Code
属性(public int Code {get; set;}
),它必须由StructureMap使用StructureMap注入。配置文件
到目前为止,我在StructureMap.config中有:
<StructureMap MementoStyle="Attribute">
<DefaultInstance
PluginType="MyApp.Plugins.Abstract.IMainPlugin, MyApp.Domain"
PluggedType="MyApp.Plugins.TimePlugin, MyApp.Plugins" />
</StructureMap>
如何在此默认实例中添加ClockPlugin
并自动设置Code
?
根据文档:
例如:基本构造函数或setter参数只是在Xml节点
中定义为属性
<StructureMap MementoStyle="Attribute">
<DefaultInstance
PluginType="StructureMap.Testing.Widget.IWidget,StructureMap.Testing.Widget"
PluggedType="StructureMap.Testing.Widget.ColorWidget,StructureMap.Testing.Widget"
Scope="Singleton"
Color="Red" />
</StructureMap>
应该设置Color
属性为Red