Does anyone know how to implement MediatR in a console application, to call a handler function using the _mediatr.Send(obj) syntax. I'm using the .Net 6 framework. Thanks for the help.
Asked
Active
Viewed 2,170 times
1 Answers
12
First, you must install these packages:
Then you can get IMediator
from DI
and use it.
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
var serviceCollection = new ServiceCollection()
.AddMediatR(Assembly.GetExecutingAssembly())
.BuildServiceProvider();
var mediator = serviceCollection.GetRequiredService<IMediator>();
//mediator.Send(new Command());

Farhad Zamani
- 5,381
- 2
- 16
- 41