zoukankan      html  css  js  c++  java
  • 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 配制

    <?xml version="1.0" encoding="utf-8" ?>
    <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 是用来定义配制文件结构的

    注意:

    1. 可以配制生命周期:lifestyle=singleton|thread|transient|pooled|custom|
    2. 配制构造函数:<parameters>....<参数名>值</参数名>....</parameters>
    <?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}
  • 相关阅读:
    Matlab实现图像切割
    Android --------------------ActionBar 与 ViewPager 和 ActionTab 切换 的源代码实现
    算法导论--装备线调度(升序&amp;&amp;降序输出)
    《打造七星级团队》观后感
    系统架构师秘籍(一)软件架构
    jQuery $.extend()使用方法
    Hadoop自学笔记(五)配置分布式Hadoop环境
    delete与delete [] 真正差别
    LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
    weblogic stuck实验2014-11-14
  • 原文地址:https://www.cnblogs.com/sgciviolence/p/1223691.html
Copyright © 2011-2022 走看看