Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding MediatR service

I want to add MediatR to my services.

Here is the code:

public class Program
{
   public static async Task Main(string[] args)
   {
      var builder = WebApplication.CreateBuilder(args);
      builder.Services.AddMediatR(Assembly.GetExecutingAssembly());
   }
   // rest of codes ...
}

Here is the Error:

Error CS1503 Argument 2: cannot convert from 'System.Reflection.Assembly' to 'System.Action<Microsoft.Extensions.DependencyInjection.MediatRServiceConfiguration>'

like image 731
Mustafa Bazghandi Avatar asked Sep 14 '25 04:09

Mustafa Bazghandi


1 Answers

If you are using [email protected] you can use this:

builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));

If you still want to use your version of code, then you should install MediatR.Extensions.Microsoft.DependencyInjection package but you might need to downgrade MediatR version to 11

like image 159
frenzy_funky Avatar answered Sep 15 '25 18:09

frenzy_funky