castle 组件化开发应用配制示例
生活随笔
收集整理的這篇文章主要介紹了
castle 组件化开发应用配制示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
示例
Windsor 實現IOC容器配制, 暴露接口,通過配制文件指定接口實現,從而降低系統內部依賴 C# Code:
IWindsorContainer?container?=?????????????????new?WindsorContainer(
????????????????????new?XmlInterpreter(new?ConfigResource("castle")));
Interface1?myInstance=?container.Resolve<Interface1>("Interface1");
//?or?
myInstance=?container.Resolve<Interface1>();
?App.Config or Web.config 配制
<configuration>
??<configSections>
????<section??name="castle"???type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler,?Castle.Windsor"?/>
??</configSections>
??<castle>?????
????<include?uri="file://castleconfiguration.xml"/>????
??</castle>
</configuration>
castleconfiguration.xml? 如果是window應用程序,需要把此配制文件copy到bin目錄。Windsor Schema 是用來定義配制文件結構的
注意:
?
<?xml?version="1.0"?encoding="utf-8"??><configuration?xmlns="MyWindsorSchema">
??<components>
????<component?id="httpservicewatcher"??type="GettingStartedPart1.HttpServiceWatcher,?GettingStartedPart1">
??????<parameters>????????
????????<notifiers>
??????????<array>
????????????<item>${email.notifier}</item>
????????????<item>${alarm.notifier}</item>
??????????</array>
????????</notifiers>
????????<Url>different?url</Url>
??????</parameters>
????</component>
????<component??id="email.notifier"??service="GettingStartedPart1.IFailureNotifier,?GettingStartedPart1"??type="GettingStartedPart1.EmailFailureNotifier,?GettingStartedPart1"?/>
????<component??id="alarm.notifier"??service="GettingStartedPart1.IFailureNotifier,?GettingStartedPart1"??type="GettingStartedPart1.AlarmFailureNotifier,?GettingStartedPart1"?/>
????<component??id="form.component"??type="GettingStartedPart1.Form1,?GettingStartedPart1"??/>
????<component??id="Interface1"?????service="GettingStartedPart1.Interface1,?GettingStartedPart1"?type?="GettingStartedPart1.Class1,?GettingStartedPart1"?lifestyle="transient"?/>
????<component??id="Interface2"?????service="GettingStartedPart1.Interface1,?GettingStartedPart1"?type?="GettingStartedPart1.Class2,?GettingStartedPart1"?lifestyle="transient"?/>??????
??</components>??
</configuration>
?
Service look up notation
The following notation is used to describe a service reference.
${componentid}
Configuration Property evaluation
This notation is used with a properties node and allows the developer to expand the value on the properties node to as a node value or attribute value. #{propertyname}?
?
?
?
轉載于:https://www.cnblogs.com/sgciviolence/archive/2008/06/17/1223691.html
總結
以上是生活随笔為你收集整理的castle 组件化开发应用配制示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [zt]摘抄
- 下一篇: [导入]DotNet软件开发框架