- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 .Net Core 应用程序,我在其中使用 .AddMediatR 扩展名为我的命令和处理程序注册程序集
In ConfigureServices in Startup.cs i have used the extension methodfrom the official packageMediatR.Extensions.Microsoft.DependencyInjection with the followingparameter:
startup.cs
services.AddBLL();
DependencyInjection.cs
public static IServiceCollection AddBLL(this IServiceCollection services)
{
services.AddAutoMapper(Assembly.GetExecutingAssembly());
services.AddMediatR(Assembly.GetExecutingAssembly());
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPerformanceBehaviour<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestValidationBehavior<,>));
return services;
}
commandhandler类如下:ListEpostaHesapariHandler.cs
public class ListEpostaHesaplariRequest : IRequest<ResultDataDto<List<ListEpostaHesaplariDto>>>
{
public FiltreEpostaHesaplariDto Model { get; set; }
}
public class ListEpostaHesaplariHandler : IRequestHandler<ListEpostaHesaplariRequest, ResultDataDto<List<ListEpostaHesaplariDto>>>
{
private readonly IBaseDbContext _context;
private readonly IMapper _mapper;
public ListEpostaHesaplariHandler(IBaseDbContext context, IMapper mapper)
{
_context = context;
_mapper = mapper;
}
public async Task<ResultDataDto<List<ListEpostaHesaplariDto>>> Handle(ListEpostaHesaplariRequest request, CancellationToken cancellationToken)
{
await Task.Delay(1);
var resultDataDto = new ResultDataDto<List<ListEpostaHesaplariDto>>() { Status = ResultStatus.Success };
try
{
var foo = _context.EpostaHesaplari;
var filtreliEpostaHesaplari = Filtre(request.Model, foo);
var epostaHesaplariDto = _mapper.Map<List<ListEpostaHesaplariDto>>(filtreliEpostaHesaplari);
resultDataDto.Result = epostaHesaplariDto;
}
catch (Exception ex)
{
resultDataDto.Status = ResultStatus.Error;
resultDataDto.AddError(ex.Message);
}
return resultDataDto;
}
这是我使用 MediatR 的 Controller
BaseController.cs
public abstract class BaseController : Controller
{
private IMediator _mediator;
public static int? birimIDD;
protected IMediator Mediator
{
get
{
return _mediator ??= HttpContext.RequestServices.GetService<IMediator>();
}
}
}
HomeController.cs
[HttpPost]
public async Task<IActionResult> MailGonderAsync()
{
FiltreEpostaHesaplariDto filtre = new FiltreEpostaHesaplariDto();
filtre.Durum = true;
var req = new ListEpostaHesaplariRequest() { Model = filtre };
var response = await Mediator.Send(req);
}
no problem so far await Mediator.Send(req); this response is coming successfully
问题从这里开始
send.cs(在类业务逻辑层)
public class EmailSend : IEmailSingleSender
{
private readonly IMediator _mediator;
public EmailSend(IMediator mediator)
{
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
}
public async Task Send(EmailParamsDto emailParamsDto)
{
try
{
FiltreEpostaHesaplariDto filtre = new FiltreEpostaHesaplariDto();
filtre.Durum = true;
var req = new ListEpostaHesaplariRequest() { Model = filtre };
var response = await _mediator.Send(req);
SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = _emailSetting.Port;
smtpClient.Host = _emailSetting.Server;
smtpClient.EnableSsl = _emailSetting.UseSsl;
NetworkCredential networkCredential = new NetworkCredential();
networkCredential.UserName = _emailSetting.UserName;
networkCredential.Password = _emailSetting.Password;
smtpClient.Credentials = networkCredential;
MailMessage mail = new MailMessage();
mail.IsBodyHtml = _emailSetting.IsHtml;
mail.From = new MailAddress(_emailSetting.UserName, emailParamsDto.Subject);
mail.To.Add(new MailAddress(emailParamsDto.Receiver));
//mail.CC.Add(_emailSetting.AdminMail);
mail.Body = emailParamsDto.Body;
mail.Subject = emailParamsDto.Subject;
mail.Priority = emailParamsDto.MailPriority;
await smtpClient.SendMailAsync(mail);
}
catch (Exception ex)
{
throw ex;
}
}
}
当这行在 Send 方法中执行时,我得到了异常:
var response = await _mediator.Send(req);
Error constructing handler for request of typeMediatR.IRequestHandler
2[IUC.BaseApplication.BLL.Handlers.Yonetim.EpostaHesaplariHandlers.ListEpostaHesaplariRequest,IUC.BaseApplication.COMMON.Models.ResultDataDto
1[System.Collections.Generic.List`1[IUC.BaseApplication.BLL.Models.Yonetim.EpostaHesaplariDto.ListEpostaHesaplariDto]]].Register your handlers with the container. See the samples in GitHubfor examples.
最佳答案
services.AddMediatR(Assembly.GetExecutingAssembly());
你所有的处理程序和命令都在你传递的这个程序集中?
关于c# - MediatR 错误 : Register your handlers with the container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64200273/
我正在更新a boilerplate中使用的babel包,从 babel-core、babel-register 等到@babel/core、@babel/register > 等 问题:在 npm
为了在 Babel 中进行运行时转换,您需要 require 并使用 babel-core/register。我不知道 register 在这个意义上意味着什么,即实际的定义。 The page is
我们可以使用“babel-register”即时转换源代码 https://babeljs.io/docs/usage/require/ 但我无法验证要使用哪一个: require('babel-co
我有一个用 RAL 建模的大寄存器映射,我想随机化一些寄存器。如果我想单独限制寄存器,那么这很简单: reg_model.register_a.randomize() with {value > 5;
我正在尝试制作一个使用 django 内置用户模型的简单应用程序。我已经创建了一个注册页面,但是当我运行服务器时,我在索引页面上收到此错误。这是我正在使用的代码: 注册.html {% extend
我正在尝试制作一个使用 django 内置用户模型的简单应用程序。我已经创建了一个注册页面,但是当我运行服务器时,我在索引页面上收到此错误。这是我正在使用的代码: 注册.html {% extend
在下面的应用程序中,我尝试将 id 动态添加到生成的项目中。我的代码工作正常,但是当我在其中添加以下两行注释时。它抛出错误 Uncaught Ext.AbstractManager.register(
当我尝试运行 SignUpFragmentTest 类时,出现错误“未注册检测!必须在注册检测下运行”。我认为当我使用@Rule 时会抛出错误。 import android.support.test
到目前为止,我目前的理解是:movq %rdi, %rax 将值从寄存器 %rdi 移动到寄存器 %rax 和movq (%rdi), %rax 会将内存中的值从(%rdi) 移动到寄存器%rax 但
我做了一个common view,所有页面都需要这个view。所以无论我需要什么,我都将这个 View 称为 xtype 。在这个公共(public) View 中,有一些组件由 id 值定义。 根据
app.get("/register", function(req, res) { res.render("register"); }); app.get("register", function(r
我目前正在开发我的个人网站 和我的网站的一部分,我有偏见的公关,以避免重复的代码... 这个 View 我有一个dojox.grid.datagrid ... 我可以在同一页面中两次调用此 View
调试版本对我来说工作正常。当我选择Active Build Variant = release,并尝试运行Build-> Generate Bundle(s)/ APK(s)-> Build APK时
我创建了一个异步函数如下: let createUserWrapper = async function(user){ await Log.createUser(use
我在 Dojo 的内容 Pane 中遇到问题,它出现一秒钟,然后内容消失。我收到以下错误: Uncaught ReferenceError: dijit is not defined index.p
我正在尝试在前端使用 React 创建一个注册表单,并在后端使用 Typescript 创建 Express 和 MongoDB atlas。当我单击提交按钮时,没有任何反应,但是当我使用 Postm
我已经使用 graph ql(具有非常基本的模式)创建了一个 Node js 项目,但是当我在为 graphql 和 graphiql 注册插件后尝试启动服务器时,我收到注册丢失错误。下面是我的代码
我的计算机体系结构书籍解释说 "Since writes to the register file are edge-triggered, our design can legally read an
我有一个 Google Pub/Sub 项目并创建了一个主题和一个简单的订阅。 但是,在指定用于推送的 URL 时,我不断收到以下错误。我已经完成了站点验证过程并在 API 和服务中注册了域,如 ht
您好,我在再次选择 DOJO 中的下拉菜单时遇到错误 function onReportTypesSelect() { if(
我是一名优秀的程序员,十分优秀!