I am getting an error while trying resolving with Unity.
Microsoft.Practices.Unity.ResolutionFailedException occurred
HResult=0x80131500
Message=Resolution of the dependency failed, type = "Dell.EMC.CPM.Core.MessageCenter.Sender.ISenderService", name = "(none)".
Exception occurred while: Calling constructor Microsoft.Practices.Unity.InterceptionExtension.PolicyInjectionBehavior(Microsoft.Practices.Unity.InterceptionExtension.CurrentInterceptionRequest interceptionRequest, Microsoft.Practices.Unity.InterceptionExtension.InjectionPolicy[] policies, Microsoft.Practices.Unity.IUnityContainer container).
Exception is: NullReferenceException - Object reference not set to an instance of an object.
Inner Exception 1:
NullReferenceException: Object reference not set to an instance of an object.
I am using Unity.Interception.NetCore Unity.NetCore nuget packages in my C# core console application.
Search the web and didn't find any clue why I am getting this error. Here is my code:
My Interface:
public interface ISenderService
{
[CommandSaving]
Task<MessageResponse> SendRequest(MessageRequest req);
}
My derived class:
public class MassTransitSenderService : ISenderService
{
...
public async Task<MessageResponse> SendRequest(MessageRequest req)
{
...
}
}
HandlerAttribute class:
public class CommandSavingAttribute : HandlerAttribute
{
public string Topic // Topic is a named parameter
{ get; set; }
public override ICallHandler CreateHandler(IUnityContainer container)
{
return new CommandSavingCallHandler();
}
}
ICallHandler class:
public class CommandSavingCallHandler : ICallHandler
{
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
Logger.Log("Log CommandSavingCallHandler");
}
and the code of the resolving:
var container = new UnityContainer();
container.RegisterType<ISenderService, MassTransitSenderService>(
new InterceptionBehavior<PolicyInjectionBehavior>(),
new Interceptor<InterfaceInterceptor>());
container.AddNewExtension<Interception>();
container.Configure<Interception>().SetInterceptorFor<ISenderService>(
new InterfaceInterceptor());
var massTransitsenderService = container.Resolve<ISenderService>();
When I delete the [CommandSaving] that located in my interface above the function I want to Intercepate, I get not error.
Any ideas what is the problem?
User contributions licensed under CC BY-SA 3.0