Create Contactor with paramater for ExternalAction

37 Views Asked by At

How I can create Contactor in code effect for ExternalAction , I have this code

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

And I want send email when success Evaluate but without write send code in SendEmail, I want use call interface to send it , like this

    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);
    }
1

There are 1 best solutions below

0
On

You are trying to use the instance action method. For the engine to be able to invoke such a method it needs to instantiate your type. Your Service class doesn't have an empty (parameterless/default) constructor. Obviously, the engine won't have an instance of your EmailService at evaluation time. Therefore, it can't invoke your instance method. Either add a default constructor to your Service class and find another way to pass EmailService to the Service class or use a static method with value type parameters.