首页 > 解决方案 > 如何将实体传递给 MediatR(我尝试时遇到问题)

问题描述

我做了下面的类,但我有一个错误我想要做的是为所有查询创建一个通用类抛出 MediatR

这是我的课

public class GetAllBaseQuery<T> : IRequest<IResponseDTO>
    where T :class
{

    public class GetAllBaseQueryHandler<T> : IRequestHandler<GetAllBaseQuery<T>, IResponseDTO>
        where T : class
    {
        private readonly IBaseResponse _Repo;
        public GetAllBaseQueryHandler(IBaseResponse Repo)
        {
            _Repo = Repo;
        }
        public async Task<IResponseDTO> Handle(GetAllBaseQuery<T> query, CancellationToken cancellationToken)
        {
            var _rec= await _Repo.GetS<T>();
            if (_rec== null)
            {
                return null;
            }
            return _rec;
        }
    }
}

这是错误信息

Register your handlers with the container. See the samples in GitHub for examples

标签: c#.net-corecontainershandlermediatr

解决方案


推荐阅读