Unity似乎提供了2种不同的途径来实现AoP功能。Unity ICallHandler与IInterceptionBehavior
问题是为什么?有什么区别?每种方法的优缺点是什么?
例如使用ICallHandler:
unity.Configure<Interception>()
.AddMatchingRule(
new TypeMatchingRule(typeof (ComplexEntity))
).AddMatchingRule(
new TypeMatchingRule(typeof (ComplexEntity.InnerEntity))
).AddMatchingRule(
new MemberNameMatchingRule("*")
).AddCallHandler(
new CallHandler()
);
但也可以代替ICallHandler使用IInterceptionBehavior来实现类似的功能
unity.RegisterType<ComplexEntity,ComplexEntity>
(new VirtualMethodInterceptor(), new InterceptionBehavior)
还有一个混合的地方,可以让你设置的拦截,但使用呼叫处理程序,例如。
unity.Configure<Interception>()
.SetInterceptorFor<ComplexEntity>(new VirtualMethodInterceptor())
.AddPolicy("TestPolicy")
.AddMatchingRule(
new TypeMatchingRule(typeof (ComplexEntity))
).AddMatchingRule(
new TypeMatchingRule(typeof (ComplexEntity.InnerEntity))
).AddMatchingRule(
new MemberNameMatchingRule("*")
).AddCallHandler(
new CallHandler()
);
那么,哪一个使用?为什么在单个框架中看似多余的解决方案?
一个问题: 这是否意味着PIAB将在未来版本的Entlib中过时?所以没有办法为IInterfaceBehaviors应用匹配规则? 如果不是,实现顶层类和相应接口(例如IBf和Bf)时,是否只有一次注册它们的方法是通过命名约定来完成的?并建立一个名称空间过滤器,并在该名称空间内循环所有类。 – Legends 2015-04-21 20:13:04
这将取决于Entlib的所有者。我不再在这个团队中(已经有几年没有),也没有对他们的计划有任何洞察力。 – 2015-04-21 22:27:42