为 ExternalAction 创建带有参数的 Contactor

问题描述

如何在代码效果中为 ExternalAction 创建 Contactor , 我有这个代码

 [ExternalAction(typeof(Service),"SendEmail")]

并且我想在成功评估时发送电子邮件但没有在 SendEmail 中编写发送代码,我想使用调用接口发送它,就像这样

    private readonly IEmailService email;
    public Service(IEmailService emailService)
    {
        email = emailService;
    }
 [Action("Send Email","Send Email to Someone")]
    public void SendEmail(Rule Rule,[Parameter(ValueInputType.User,Description = "Output message",DataSourceName = "UserList")] int userId)
    {
      email.sene(userId);
    }

解决方法

您正在尝试使用实例操作方法。为了让引擎能够调用这样的方法,它需要实例化您的类型。您的 Service 类没有空的(无参数/默认)构造函数。显然,引擎在评估时不会有您的 EmailService 实例。因此,它无法调用您的实例方法。要么向您的 Service 类添加一个默认构造函数,并找到另一种将 EmailService 传递给 Service 类的方法,要么使用带有值类型参数的静态方法。