ましょう私が最初に働いているシナリオを示しています。私はそれを使用するインターフェイスを実装するとHandlerAttributeの代行受信が可能ですか?
私はこの方法のように登録InterfaceInterceptor使ってAOPで取り組んでいるHandlerAttributeあります
public void RegisterType<TInterface, TClass>()
where TClass : TInterface
{
// My UnityContainer
this.container.RegisterType<TInterface, TClass>(new ContainerControlledLifetimeManager())
.Configure<Interception>()
.SetDefaultInterceptorFor<TInterface>(new InterfaceInterceptor());
}
HandlerAttributeを持つインタフェース:
をpublic interface IService<TId, TEntity>
where TId : IEquatable<TId>
where TEntity: AbstractEntity<TId> // Class that has a Id
{
[DatabaseTransaction] // The HandlerAttribute
void Update(TEntity entity);
}
したがって、私はIServiceを実装するMyServiceを作成し、RegisterTypeメソッドを使用して登録します。だから、その後私はIServiceを渡すmyContainerからResolveメソッドを呼び出して、私は私のDatabaseTransactionAttributeによって傍受私の方法Updateとサービスを使用します。
public class MyService : IService<int, MyEntity>
{
}
後:
RegisterType<IService, MyService>()
私が作成まで、すべてOK IServiceを実装するインタフェースIMyService、およびIMyServiceを実装するMyServiceがあります。
RegisterType<IMyService, MyService>()
問題であり、私は後者の場合でUpdateメソッドを呼び出して、私のDatabaseTransactionAttribute:私は
public class IMyService : IService<int, MyEntity>
{
}
public class MyService : IMyService
{
}
後...上記IMyServiceインターフェイスを登録し、解決するために同じ手順を実行しますもう方法を傍受しない、誰もがなぜ知っている?私はいくつかの方法であり、この質問、関連見つかっ
:だからCan a C# class inherit attributes from its interface?
を、私は属性を持つインタフェースを実装するインターフェイスで再宣言する必要がありますか? OO
インターセプタは、属性が単一性コンテナに登録されているインターフェイスにある場合にのみ機能しますか?