2

Let's me show first the scenario that is working:

I have a HandlerAttribute that is working with AOP using InterfaceInterceptor that i register like this way:

public void RegisterType<TInterface, TClass>()
        where TClass : TInterface
{   
    // My UnityContainer         
    this.container.RegisterType<TInterface, TClass>(new ContainerControlledLifetimeManager())
        .Configure<Interception>()
        .SetDefaultInterceptorFor<TInterface>(new InterfaceInterceptor());
}

The interface that has the 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);
}

So, i create the MyService that implements IService, and i register using the method RegisterType. So, after that i call the Resolve method from myContainer passing the IService, and i use the service with my method Update intercepted by my DatabaseTransactionAttribute:

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

After:

RegisterType<IService, MyService>()

All ok until i create the interface IMyService, that implements IService, and MyService implementing IMyService. I do the same step to register and resolve the IMyService interface mentioned above...

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

public class MyService : IMyService
{
}

After:

RegisterType<IMyService, MyService>()

the problem is, when i call the Update method in the second case, my DatabaseTransactionAttribute doesn't intercept the method anymore, anyone knows why?


I found this question that is in some way, related: Can a C# class inherit attributes from its interface?

So, i have to re-declare in the interface that implements the interface that has the attribute? Oo

The interceptor only works if the attribute is in the interface that is registered in the unity container?

Community
  • 1
  • 1
Vinicius Ottoni
  • 4,631
  • 9
  • 42
  • 64

1 Answers1

3

AFAIK:

The interceptor only works if the attribute is in the interface that is registered in the unity container?

Yes

So, i have to re-declare the attribute in the interface that implementsextends the interface that has the attribute?

Yes

onof
  • 17,167
  • 7
  • 49
  • 85