Closed longvietcode closed 10 months ago
I think the issue is that you only register Mediatr request handlers from the assembly containing the class Program. The request handlers are in a different assembly, the application project.
Same as #976.
I think the issue is that you only register Mediatr request handlers from the assembly containing the class Program. The request handlers are in a different assembly, the application project.
Same as #976.
Thanks for the comments, do you guys have the code example for how I can register IRequestHandler in my Application layer? Thanks!
I think the issue is that you only register Mediatr request handlers from the assembly containing the class Program. The request handlers are in a different assembly, the application project.
Same as #976.
Thanks for the comments, do you guys have the code example for how I can register IRequestHandler in my Application layer? Thanks!
All you need to do is amend the code in Program.cs that calls AddMediatr. This currently takes the type 'Program' which makes Mediatr add DI registration for any request handlers that are in Program's project. As there are no request handlers in that project, none are added. Instead of passing the type Program, pass a type from the Application project which contains the handlers.
I think the issue is that you only register Mediatr request handlers from the assembly containing the class Program. The request handlers are in a different assembly, the application project.
Same as #976.
Thanks for the comments, do you guys have the code example for how I can register IRequestHandler in my Application layer? Thanks!
All you need to do is amend the code in Program.cs that calls AddMediatr. This currently takes the type 'Program' which makes Mediatr add DI registration for any request handlers that are in Program's project. As there are no request handlers in that project, none are added. Instead of passing the type Program, pass a type from the Application project which contains the handlers.
It works, thank you so much
I think the issue is that you only register Mediatr request handlers from the assembly containing the class Program. The request handlers are in a different assembly, the application project.
Same as #976.
Thanks for the comments, do you guys have the code example for how I can register IRequestHandler in my Application layer? Thanks!
All you need to do is amend the code in Program.cs that calls AddMediatr. This currently takes the type 'Program' which makes Mediatr add DI registration for any request handlers that are in Program's project. As there are no request handlers in that project, none are added. Instead of passing the type Program, pass a type from the Application project which contains the handlers.
It works, thank you so much
What was the type from the Application project that you passed?
Remember that you can pass the 'array' as an argument into mediatR configuration. It seems that Program.cs assembly just contains the IMediatR <-- probably u use it only for initializing your query/command flow from controllers. However, the real handlers are in the Application Layer for example. So just add one more assembly
builder.Services.AddMediatR(cfg => { cfg.RegisterServicesFromAssemblies([typeof(Program).Assembly, typeof(xxxxxx).Assembly]); });
If your handlers are in a separate project, an alternative is to register the assembly of that project explicitly.
var assemblies = Assembly.Load("YourOther.ProjectWithHandlers");
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(assemblies));
I think the issue is that you only register Mediatr request handlers from the assembly containing the class Program. The request handlers are in a different assembly, the application project.
Same as #976.
Thanks for the comments, do you guys have the code example for how I can register IRequestHandler in my Application layer? Thanks!
All you need to do is amend the code in Program.cs that calls AddMediatr. This currently takes the type 'Program' which makes Mediatr add DI registration for any request handlers that are in Program's project. As there are no request handlers in that project, none are added. Instead of passing the type Program, pass a type from the Application project which contains the handlers.
Thank you
So i'm new to MediatR and I got this error, please help me, thanks! _ Version: .NET 8 MediatR 12.2.0
This is my solution structure:
This is my Program file:
This is my controller file:
This is where I implement MediatR request and request handler