Interception at one level works...
ControllerA(IBusinessServiceA businessService)
BusinessService is injected, I see WillExecute, GetRequiredInterfaces, Invoke all run
Interception 2-deep does not work...
ControllerB(IBusinessServiceB businessService)
BusinessServiceB(IDal dal)
I see Will Execute, GetRequiredInterfaces for Dal, and I see the DAL constructor fire, I see the BusinessServiceB constructor fire. WillExecute and GetRequiredInterfaces fire, then I get an exception.
container.RegisterType<IBusinessServiceA, BusinessServiceA>(new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<MyInterceptionBehaviorA>());
container.RegisterType<IBusinessServiceB, BusinessServiceB>(new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<MyInterceptionBehaviorA>());
container.RegisterType<IDal, Dal>(new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<MyInterceptionBehaviorB>());
Works fine with normal registration.
container.RegisterType<IBusinessServiceA, BusinessServiceA>();
container.RegisterType<IBusinessServiceB, BusinessServiceB>();
container.RegisterType<IDal, Dal>();
Here's the exception...
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Overriding address(es) 'http://localhost:53382/'. Binding to endpoints defined in UseKestrel() instead.
Hosting environment: Development
Content root path: c:\users\scovel\Source\Repos\TestUnity\TestUnity
Now listening on: http://127.0.0.1:8088
Application started. Press Ctrl+C to shut down.
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLDAT7258BVT", Request id "0HLDAT7258BVT:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: Unable to resolve service for type 'TestUnity.Implementations.IBusinessServiceB' while attempting to activ
ate 'TestUnity.Controllers.ValuesControllerB'.
at Microsoft.Extensions.Internal.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParamete
rRequired)
at lambda_method(Closure , IServiceProvider , Object[] )
at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass4_0.b__0(ControllerContext controll
erContext)
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.g__CreateController|0(Con
trollerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIIndexMiddleware.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.d__2.MoveNext()
Interception at one level works...
ControllerA(IBusinessServiceA businessService)
BusinessService is injected, I see WillExecute, GetRequiredInterfaces, Invoke all run
Interception 2-deep does not work...
ControllerB(IBusinessServiceB businessService)
BusinessServiceB(IDal dal)
I see Will Execute, GetRequiredInterfaces for Dal, and I see the DAL constructor fire, I see the BusinessServiceB constructor fire. WillExecute and GetRequiredInterfaces fire, then I get an exception.
container.RegisterType<IBusinessServiceA, BusinessServiceA>(new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<MyInterceptionBehaviorA>());container.RegisterType<IBusinessServiceB, BusinessServiceB>(new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<MyInterceptionBehaviorA>());container.RegisterType<IDal, Dal>(new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<MyInterceptionBehaviorB>());Works fine with normal registration.
container.RegisterType<IBusinessServiceA, BusinessServiceA>();container.RegisterType<IBusinessServiceB, BusinessServiceB>();container.RegisterType<IDal, Dal>();Here's the exception...
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Overriding address(es) 'http://localhost:53382/'. Binding to endpoints defined in UseKestrel() instead.
Hosting environment: Development
Content root path: c:\users\scovel\Source\Repos\TestUnity\TestUnity
Now listening on: http://127.0.0.1:8088
Application started. Press Ctrl+C to shut down.
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLDAT7258BVT", Request id "0HLDAT7258BVT:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: Unable to resolve service for type 'TestUnity.Implementations.IBusinessServiceB' while attempting to activ
ate 'TestUnity.Controllers.ValuesControllerB'.
at Microsoft.Extensions.Internal.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParamete
rRequired)
at lambda_method(Closure , IServiceProvider , Object[] )
at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass4_0.b__0(ControllerContext controll
erContext)
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.g__CreateController|0(Con
trollerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIIndexMiddleware.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.d__2.MoveNext()