UnityはAoP機能を実現するために2つの異なるルートを提供しているようです。
問題はなぜですか?違いは何ですか?各アプローチの長所と短所は何でしょうか?
たとえば、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()
);
では、どちらを使用しますか?単一のフレームワークに一見冗長なソリューションがあるのはなぜですか?