0

Im trying to create a query\command through Mediatr library with generic parameter but when runnnig Send method its throw an exception

System.InvalidOperationException: Handler was not found for request

My code is below:

public class ConfigureOutputModel
    {
        public int Id { get; set; }

        public string Code { get; set; }

        public string Description { get; set; }

        public bool IsActive { get; set; }

        public bool SystemReserved { get; set; }

    }

   public class UpdateConfigure<T> : IRequest<ConfigureOutputModel>
    {
        public T EntityDb { get; set; }
     
        public class UpdateConfigureHandler : IRequestHandler<
            UpdateConfigure<T>,
            ConfigureOutputModel>
        {
            private readonly IConfigureRepository _repository;
            private readonly ITypeComposer _typeNameComposer;

            public UpdateConfigureHandler(IConfigureRepository repository,
                ITypeComposer typeNameComposer)
            {
                _repository = repository;
                _typeNameComposer = typeNameComposer;
            }

            public Task<ConfigureOutputModel> Handle(UpdateConfigure<T> request, CancellationToken cancellationToken)
            {
               //...some code here
            }

        }
    }

Call from my Api Controller method

ConfigureOutputModel outputModel = new ConfigureOutputModel();
UpdateConfigure<ConfigureOutputModel> updateConfigure =
                new UpdateConfigure<ConfigureOutputModel>() {EntityDb = outputModel};
var query = await this.Send(updateConfigure);
  • What is your configure in startup.cs? You can check [this](https://stackoverflow.com/questions/56415440/the-program-is-not-able-to-find-handler-for-mediatr-query-asp-net-core) – Jerry Cai Apr 29 '21 at 05:58
  • My configure is services.AddMediatR(Assembly.GetExecutingAssembly()) I think the problem has to do with the generic parameter – Manos Kanellopoulos Apr 29 '21 at 13:41

0 Answers0