1

私は自分のプロジェクトでベースのインターセプトを使用したいと考えています[HandlerAttribute](新しい開発者にとっては少し明白だからです)。ただし、明示的に指定new InterceptionBehavior<PolicyInjectionBehavior>()しない限り、動作させることはできませんRegisterType

通話[HandlerAttribute]を汚染することなく、すべての検出を有効にする簡単な方法はありますか?RegisterType

4

1 に答える 1

1

私は次のことがあなたが求めているものを達成するはずだと思います

UnityContainerExtensionそのように定義します:

public class InterceptionExtension : UnityContainerExtension
{
    protected override void Initialize()
    {
        Context.Registering += OnRegister;
        Context.RegisteringInstance += OnRegisterInstance;
    }

    public override void Remove()
    {
        Context.Registering -= OnRegister;
        Context.RegisteringInstance -= OnRegisterInstance;
    }

    private void OnRegister(object sender, RegisterEventArgs e)
    {
        Container.Configure<Interception>()
            .SetInterceptorFor(e.TypeTo, new VirtualMethodInterceptor());
    }

    private void OnRegisterInstance(object sender, RegisterInstanceEventArgs e)
    {
        Container.Configure<Interception>()
            .SetInterceptorFor(e.RegisteredType, new VirtualMethodInterceptor());
    }
}

これをコンテナに追加します。

_container.AddNewExtension<InterceptionExtension>();

次に、登録されているすべてのタイプについて、Interception仮想メンバーに適用するように構成する必要があります。これにより、適用されたすべて[HandlerAttribute]のが検出されます。

于 2012-02-22T23:37:55.803 に答える