jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
10.91k stars 1.16k forks source link

Ninject binding issue with MediatR #958

Closed VinitaHotwani closed 10 months ago

VinitaHotwani commented 10 months ago

I have a controller where I inject Mediator and I am getting binding error I have API in .Net Frame work 4.7.2 Ninject - 3.2.2 Mediatr: 5.0.1 (If I upgrade also, I have issue and I tried downgrading reading previous issue Error: Error activating IntPtr No matching bindings are available, and the type is not self-bindable. Activation path: 4) Injection of dependency IntPtr into parameter method of constructor of type ServiceFactory 3) Injection of dependency ServiceFactory into parameter serviceFactory of constructor of type Mediator 2) Injection of dependency IMediator into parameter mediator of constructor of type ProcessesController 1) Request for ProcessesController

Suggestions: 1) Ensure that you have defined a binding for IntPtr. 2) If the binding was defined in a module, ensure that the module has been loaded into the kernel. 3) Ensure you have not accidentally created more than one kernel. 4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name. 5) If you are using automatic module loading, ensure the search path and filters are correct.

IKernel Container = new StandardKernel(); Container.Components.Add<IBindingResolver, ContravariantBindingResolver>(); Container.Bind(x => x.FromThisAssembly().SelectAllClasses().BindAllInterfaces()); Container.Bind(x => x.FromAssemblyContaining<IMediator>().SelectAllClasses().BindDefaultInterface()); Container.Bind<IRequestHandler<GetProcessInstanceCommentRequest, GetProcessInstanceCommentResponse>>() .To<GetCommentsHandler>();

Please let me know how I can fix this ?

jbogard commented 10 months ago

This is better for StackOverflow, I've never used Ninject.

VinitaHotwani commented 10 months ago

This is better for StackOverflow, I've never used Ninject.

I am getting below error, would you know why ? I already registered the handlers

Handler was not found for request of type MediatR.IRequestHandler`2[OdataV2.Models.GetProcessInstanceCommentRequest,OdataV2.Models.GetProcessInstanceCommentResponse]. Register your handlers with the container. See the samples in GitHub for examples.'

jbogard commented 10 months ago

The description tells you why, there's something wrong with your registration somehow. My suggestion is to eliminate MediatR from the equation and try the registration/resolution PURELY from your container and see if that works.

VinitaHotwani commented 10 months ago

You mean apart from MediatR, other registration ? That is working. Having issue with MediatR