title: Unable to resolve service for type 'MediatR.IMediator'
body: <p>I try to make .NET Core API with CQRS, but i cannot build it because of MediatR error:</p>
  
  <p>System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Core.Infrastructure.Domain.Queries.IQueryBus Lifetime: Scoped ImplementationType: Core.Infrastructure.Bus.QueryBus': Unable to resolve service for type 'MediatR.IMediator' while attempting to activate 'Core.Infrastructure.Bus.QueryBus'.)'</p>
  
  <p>I've already added 'AddScope' for my QueryBus etc. Here's my code (app for AWS):</p>
  
  <pre><code>public class Startup
      {
          public const string AppS3BucketKey = "AppS3Bucket";
  
          public Startup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public static IConfiguration Configuration { get; private set; }
  
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddControllers();
              services.AddAWSService&lt;Amazon.S3.IAmazonS3&gt;();
  
              services.AddScoped&lt;IQueryBus, QueryBus&gt;();
              services.AddScoped&lt;IWarehouseRepository, WarehouseRepository&gt;();
              services.AddScoped&lt;IRequestHandler&lt;GetAllWarehouseDepartmentsQuery, IEnumerable&lt;WarehouseDepartmentDto&gt;&gt;, WarehouseQueryHandler&gt;();
          }
  
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
  
              app.UseHttpsRedirection();
  
              app.UseRouting();
  
              app.UseAuthorization();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllers();
              });
          }
      }
  </code></pre>
  
  <p>QueryBus:</p>
  
  <pre><code>using System.Threading.Tasks;
  using Core.Infrastructure.Domain.Queries;
  using MediatR;
  
  namespace Core.Infrastructure.Bus
  {
      public class QueryBus : IQueryBus
      {
          private readonly IMediator _mediator;
  
          public QueryBus(IMediator mediator)
          {
              _mediator = mediator;
          }
  
          public Task&lt;TResponse&gt; Send&lt;TQuery, TResponse&gt;(TQuery query) where TQuery : IQuery&lt;TResponse&gt;
          {
              return _mediator.Send(query);
          }
      }
  }
  
  </code></pre>
  
  <p>IQueryBus:</p>
  
  <pre><code>using System.Threading.Tasks;
  
  namespace Core.Infrastructure.Domain.Queries
  {
      public interface IQueryBus
      {
          Task&lt;TResponse&gt; Send&lt;TQuery, TResponse&gt;(TQuery query) where TQuery : IQuery&lt;TResponse&gt;;
      }
  }
  </code></pre>
  
  <p>Thanks for help</p>