zoukankan      html  css  js  c++  java
  • castle windsor学习----- Referencing types in XML 在xm文件中引用类型

    当从xml引用installer的语法如下

    <install type="Acme.Crm.Infrastructure.ServicesInstaller, Acme.Crm.Infrastructure"/>

    Windsor允许你省略一部分命名规则。如

    <install type="Acme.Crm.Infrastructure.ServicesInstaller"/>

    甚至可以省略命名空间。如

    <install type="ServicesInstaller"/>

    当使用如上的简写语法时,Windsor将试图在应用程序域中的程序集(不包括BCL程序集)查找类型。如果你加载一些特殊的程序集(例如不在编辑期间进行依赖的程序集),

    你可以在xml文件中配置如下节点就可以添加扫描程序集了

    <using assembly="Acme.Crm.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=11111111111111" />

    你也可以使用.dll或.exe文件路径代替程序集名称

    这个方式类似c#中的using用法,这里只是引用程序集代替了命名空间

    如果没有唯一的类型被Windsor找到,则会引发异常,你将需要扩展一些信息保证类型的唯一性

    Limitations

    By default BCL types (defined in System.* assemblies or mscorlib) will not be matched when using shorthand syntax. Also arrays and generics containing BCL types will not be matched. You will have to use full type name then

    Generics

    Generic types are supported using following syntax:

    For simple generic type IGeneric<ICustomer>:

    IGeneric`1[[ICustomer]]
    

    For generic type with multiple generic parameters like IDoubleGeneric<ICustomer, ISpecification>:

    IDoubleGeneric`2[[ICustomer],[Acme.Crm.ISpecification]]
    

    Notice you can mix and match levels of details provided, specifying some types by just name, while other by namespace and name.

    For nested generic type with multiple generic parameters like IDoubleGeneric<ICustomer, IDoubleGeneric<ICustomer, IClock>>:

    IDoubleGeneric`2[[ICustomer],[IDoubleGeneric`2[[ICustomer],[IClock]]]]
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <!--<using assembly="WindsorInstaller"/>-->
      <installers>
        <install type="CustomerInstaller"/>
      </installers>
      <!--<components>
        <component type="Service.Log,Service" service="IService.ILog,IService">
          
        </component>
      </components>-->
    </configuration>

    如上配置install,如果type的值只是类型的名称,如果该类型不在当前的程序集中,则需要using引入该类型所在的程序集才能正常解析

  • 相关阅读:
    windows anaconda下安装Python的tesserocr库
    windows10上安装docker与碰到的坑
    阿里云centos下部署python flask应用。
    LeetCode--Python合并两个有序链表
    Linux(CentOS)下重置MySQL根(Root)密码,以及远程登录mysql连接IP受限问题解决
    windows下anaconda安装词云wordcloud
    关于selenium使用中谷歌浏览器驱动chromedriver的问题
    LeetCode 184. Department Highest Salary(找出每个部门中最高薪水)
    机器学习七--回归--多元线性回归Multiple Linear Regression
    机器学习六--回归--简单线性回归Simple Linear Regression
  • 原文地址:https://www.cnblogs.com/lanpingwang/p/6533766.html
Copyright © 2011-2022 走看看