Реализация Mediatr в ASP. Net WebApi2 - PullRequest
0 голосов
/ 20 марта 2020

Я пытаюсь реализовать шаблон mediatr в ASP. Net Web Api.

Получение следующей ошибки:

Не найден обработчик для запроса типа MediatR .IRequestHandler`2 [Orion_API.Campaigns.GetCampaigns.GetCampaignsRequest, System.Collections.Generi c .List`1 [Orion_API.Campaigns.GetCampaigns.GetCampaignsResponse]]. Зарегистрируйте ваши обработчики в контейнере.

Мой класс начальной загрузки выглядит следующим образом:

builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

builder.RegisterGeneric(typeof(GenericRepository<>))
       .As(typeof(IGenericRepository<>))
       .InstancePerRequest();

builder.RegisterType<Mediator>().As<IMediator>().InstancePerLifetimeScope();

builder.Register<ServiceFactory>(context =>
{
    var componentContext = context.Resolve<IComponentContext>();
    return t => {
        object o;

        return componentContext.TryResolve(t, out o) ? o : null;
    };
});


//Set the dependency resolver to be Autofac.  
Container = builder.Build();

1 Ответ

0 голосов

builder.RegisterApiControllers (Assembly.GetExecutingAssembly ());

    builder.RegisterGeneric(typeof(GenericRepository<>))
           .As(typeof(IGenericRepository<>))
           .InstancePerRequest();

    builder.RegisterType<Mediator>().As<IMediator>().InstancePerLifetimeScope();

    builder.Register<ServiceFactory>(context =>
    {
        var componentContext = context.Resolve<IComponentContext>();
        return t => {
            object o;

            return componentContext.TryResolve(t, out o) ? o : null;
        };
    });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...