2012-01-24 2 views
2

하자 내가 먼저 노력하고 시나리오 보여그것을 사용하는 인터페이스를 구현할 때 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에서 해결 방법을 호출하고 난 내 DatabaseTransactionAttribute에 의해 차단 내 방법 업데이트와 서비스를 사용

public class MyService : IService<int, MyEntity> 
{ 
} 

후 :

RegisterType<IService, MyService>() 

내가 만들 때까지 모든 확인 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

인터셉터는 속성이 단일성 컨테이너에 등록 된 인터페이스에있는 경우에만 작동합니까?

답변

3

AFAIK :

속성이 가 일치 컨테이너에 등록 된 인터페이스에있는 경우 요격에만 작동?

그래서, 내가 이 속성이있는 인터페이스를 확장 구현하는 인터페이스의 속성을 다시 선언해야?

관련 문제