zoukankan      html  css  js  c++  java
  • Unity No Policies

    Unity提供了丰富的拦截匹配策略,同时它也提供了ApplyNoPoliciesAttribute用于对特定的成员不应用拦截策略。看一个简单的示例:

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

    MyObject类型的DoWork函数不会被拦截。

  • 相关阅读:
    Leetcode题目:Remove Duplicates from Sorted List
    Leetcode题目:Lowest Common Ancestor of a Binary Search Tree
    Leetcode题目:Ugly Number
    Leetcode题目:Remove Linked List Elements
    Leetcode题目:Count and Say
    6-3 事务
    6-1 视图
    5-2 pymysql模块
    5-1 图形工具Navicat
    4-3 多表查询
  • 原文地址:https://www.cnblogs.com/junchu25/p/2633427.html
Copyright © 2011-2022 走看看