zoukankan      html  css  js  c++  java
  • Unity 配置文件 基本设置

    配置文件app.config,其中的<configSections>配置节内的信息是必加的,不然载入会出错

    View Code
    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Microsoft.Practices.Unity.Configuration"/>
      </configSections>
      <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
        <alias alias="IValueProvider" type="Common.IValueProvider,Common"/>
        <container name="ValueProviders">
          <register type="IValueProvider" name="Memery" mapTo="ValueProviders.MemeryProvider,ValueProviders"/>
          <register type="IValueProvider" name="Viedo" mapTo="ValueProviders.VideoCardProvider,ValueProviders"/>
          <register type="IValueProvider" name="Date" mapTo="ValueProviders.DateProvider,ValueProviders"/>
          <register type="IValueProvider" name="Name" mapTo="ValueProviders.NameProvider,ValueProviders"/>
        </container>
      </unity>
      <startup>
        <supportedRuntime version="v2.0.50727"/>
      </startup>
    </configuration>

    在Common程序集中的接口:

        public interface IValueProvider
        {
            string GetValue(object key);
        }

    在ValueProviders程序集中的其中一个接口实例:

        public  class DateProvider:IValueProvider
        {
            public string GetValue(object key)
            {
                return DateTime.Now.ToShortDateString();
            }
        }

    调用方法:

                UnityContainer container = new UnityContainer();
                container.LoadConfiguration("ValueProviders");
                var provider= container.Resolve<Common.IValueProvider>("Viedo");
                provider.GetValue(null);

    如果不带参数,直接LoadConfiguration,会载入名称为”“或者没有name属性的container配置节,如果都没有会报错

  • 相关阅读:
    部署IIS HTTP 错误 500.19
    G2 V4 异步加载数据--Angular
    G2 V4 异步加载数据 分组柱状图X轴Y轴显示异常
    Angular G2 数据覆盖Y轴
    G2 RangeError: toFixed() digits argument must be between 0 and 100
    win7下users用户文件转移到其他盘符
    配置JDK和Tomcat环境变量
    oracle中exp,imp的使用详解
    c# 判断字符串中是否含有汉字,数字
    针对oracle集群的连接配置
  • 原文地址:https://www.cnblogs.com/FlyCat/p/2703997.html
Copyright © 2011-2022 走看看