現在、Castle DynamicProxy を使用してインターセプターを実装しています。サービス層メソッドでいくつかのカスタム属性を取得するためにインターセプターが必要ですが、invocation.Method.GetCustomAttributes は何も返しません。私が間違っている可能性はありますか?
傍受された方法:
[Transaction()]
[SecurityRole(AuthenticationRequired = false, Role = SystemRole.Unauthorised)]
public virtual void LoginUser(out SystemUser userToLogin, string username)
{
...
}
インターセプター:
// Checks that a security attribute has been defined
foreach (SecurityRoleAttribute role in invocation.Method.GetCustomAttributes(typeof(SecurityRoleAttribute), true))
{
if (!securityAttributeDefined)
securityAttributeDefined = true;
}
私も試しました:
Attribute.GetCustomAttribute(invocation.Method, typeof(SecurityRoleAttribute), true);
アップデート:
構成の問題である可能性があります。構成コードは次のとおりです。
インターセプターインストーラー:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<LoggingInterceptor>()
.Named("LoggingInterceptor"));
container.Register(
Component.For<SecurityInterceptor>()
.Named("SecurityInterceptor"));
container.Register(
Component.For<ValidationInterceptor>()
.Named("ValidationInterceptor"));
}
サービスインストーラー:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
string[] interceptors = {"LoggingInterceptor", "SecurityInterceptor"};
container.Register(AllTypes.FromAssemblyContaining<BaseService>().Pick()
.If(Component.IsInSameNamespaceAs<LoginService>())
.Configure(c => c
.LifeStyle.Transient
.Interceptors(interceptors))
.WithService.DefaultInterface());
}
Castle 2.5.2/.Net 3.5 を使用しています。
ありがとう、
ポール