Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

IRepository Interceptor #1840


User avatar
0
smcclure created

Hi,

Is there an appropriate way for me to intercept IRepository methods? Here is my current attempt.

I register my interceptor class

IocManager.IocContainer.Register(Component
                    .For<IRepository<Customer>>()
                    .Interceptors(InterceptorReference.ForType<CustomerChangeInterceptor>()).Anywhere);

At the moment, the interceptor only forwards the call

public void Intercept(IInvocation invocation)
{
    invocation.Proceed();
}

I get the following error from the UnitOfWorkInterceptor

[NullReferenceException: Object reference not set to an instance of an object.]
 Abp.Domain.Uow.UnitOfWorkAttribute.GetUnitOfWorkAttributeOrNull(MemberInfo methodInfo) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkAttribute.cs:143
   Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:25
   Castle.DynamicProxy.AbstractInvocation.Proceed() +484
   VDS.RapIDAdmin.Customers.CustomerChangeInterceptor.Intercept(IInvocation invocation) in C:\My Documents\CardSmith\Visual Studio Projects\RapIDAdmin\VDS.RapIDAdmin.Core\Customers\CustomerChangeInterceptor.cs:42
   Castle.DynamicProxy.AbstractInvocation.Proceed() +484

The error source seems to be that invocation.MethodInvocationTarget is null in the current context, so this fails in aspnetboilerplate/src/Abp/Domain/Uow/UnitOfWorkInterceptor.cs (line 24)

var unitOfWorkAttr = UnitOfWorkAttribute.GetUnitOfWorkAttributeOrNull(invocation.MethodInvocationTarget);

Thanks, Scott


1 Answer(s)
  • User Avatar
    0
    smcclure created

    Sleep always helps. I created a custom repository implementation and it now works as expected. Thanks!