Home > Enterprise >  'IServiceCollection' does not contain a definition for 'AddMediatR' and no acces
'IServiceCollection' does not contain a definition for 'AddMediatR' and no acces

Time:05-21

I'm using .NET 6 in Program.cs:

builder.Services.AddMediatR(Assembly.GetExecutingAssembly());

I get: 'IServiceCollection' does not contain a definition for 'AddMediatR' and no accessible extension method 'AddMediatR' accepting a first argument of type 'IServiceCollection' could be found' (are you missing a using directive or an assembly reference?)

Why?

CodePudding user response:

First you must

Install-Package MediatR

then for access in IServiceCollection must

Install-Package MediatR.Extensions.Microsoft.DependencyInjection
  •  Tags:  
  • .net
  • Related