• 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函数不会被拦截。

  • 相关阅读:
    POJ3164 Command Network
    UVa11401 Triangle Counting
    UVa11174 Stand in a Line
    UVa11806 Cheerleaders
    Uva11538 Chess Queen
    Bzoj3130 [Sdoi2013]费用流
    Bzoj3262 陌上花开
    模拟25A 题解
    模拟24 题解
    模拟23 题解
  • 原文地址:https://www.cnblogs.com/junchu25/p/2633427.html
Copyright © 2020-2023  润新知