zoukankan      html  css  js  c++  java
  • Unity The Namespace Matching Rule

    Unity提供了根据名称空间进行匹配规则的类型NamespaceMatchingRule,它的通配符规则和MemberNameMatchingRule相同。看一个简单的示例:

     1 public class MyObject
     2 {
     3   public virtual void DoWork()
     4   {
     5 
     6   }
     7 
     8   public virtual void DoWork2()
     9   {
    10 
    11   }
    12 
    13   public virtual void DoWork3()
    14   {
    15 
    16   }
    17 }
    18 
    19 IUnityContainer unityContainer = new UnityContainer();
    20 
    21 unityContainer.LoadConfiguration();
    22 unityContainer.Configure<Interception>()
    23   .AddPolicy(“NamespaceMatchingRule”)
    24   .AddMatchingRule(new NamespaceMatchingRule(“UnityTest6.*”, true))
    25   .AddCallHandler<Log4NetHandler>();
    26 unityContainer.RegisterType<MyObject>(
    27   new Interceptor<VirtualMethodInterceptor>(),
    28   new InterceptionBehavior<PolicyInjectionBehavior>()
    29 );
    30 
    31 MyObject myObject = unityContainer.Resolve<MyObject>();
    32 
    33 myObject.DoWork();
    34 myObject.DoWork2();
    35 myObject.DoWork3();

    配置文件如下定义:

    <unity xmlns=”http://schemas.microsoft.com/practices/2010/unity”>
      <sectionExtension type=”Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration” />
    
      <assembly name=”mscorlib, 2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ />
      <assembly name=”UnityTest6″ />
    
      <namespace name=”UnityTest6″ />
    
      <container>
        <extension type=”Interception” />
    
        <interception>
          <policy name=”NamespacePolicy”>
            <matchingRule name=”NamespaceMatchingRule” type=”NamespaceMatchingRule”>
              <constructor>
                <param name=”namespaceName” value=”UnityTest6.*” />
              </constructor>
            </matchingRule>
            <callHandler name=”Log4NetHandler” type=”Log4NetHandler” />
          </policy>
        </interception>
    
        <register type=”MyObject”>
          <interceptor type=”VirtualMethodInterceptor” />
          <interceptionBehavior type=”PolicyInjectionBehavior” />
        </register>
      </container>
    </unity>
  • 相关阅读:
    使用Python画ROC曲线以及AUC值
    Machine Learning : Pre-processing features
    资源 | 数十种TensorFlow实现案例汇集:代码+笔记
    在 Mac OS X 终端里使用 Solarized 配色方案
    编译安装GCC 4.7.2
    Office -Word 公式插件Aurora的使用 ——在 Word 中插入 LaTex 公式
    LaTeX 写中文论文而中文显示不出来
    LaTeX 公式编辑之 把符号放在正下方
    Python 判断字符串是否含有指定字符or字符串
    Python 中使用 pandas Dataframe 删除重复的行
  • 原文地址:https://www.cnblogs.com/junchu25/p/2631621.html
Copyright © 2011-2022 走看看