I implemented a custom submit action and it works fine. But now I'm trying to store data to an external database using repository classes. For some reason it doesn't work if I add other interfaces in the constructor. Here is my code snippet:
public class CustomSubmitAction: SubmitActionBase<string>
{
private readonly ImessagingServiceRepository _messagingServiceRepository;
public CustomSubmitAction(ISubmitActionData submitActionData, ImessagingServiceRepository messagingServiceRepository) : base(submitActionData)
{
_messagingServiceRepository = messagingServiceRepository;
}
protected override bool TryParse(string value, out string target)
{
target = string.Empty;
return true;
}
protected override bool Execute(string data, FormSubmitContext formSubmitContext)
{
Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext));
if (!formSubmitContext.HasErrors)
{
var formfields = formSubmitContext.Fields;
......
// following code is mockup
// call repository using
_messagingServiceRepository.Save(model);
}
}
}
In the log it shows this warning but when I try to step thru the code it won't even hit the breakpoint on constructor:
WARN Could not find constructor in ReflectionUtil.CreateObject: Modules.ExperienceForm.CustomSubmitAction. The constructor parameters may not match or it may be an abstract class. Parameter info: Count: 1. Parameter types: Sitecore.ExperienceForms.Mvc.Models.SubmitActionData
If I leave constructor as default it works perfectly.
public CustomSubmitAction(ISubmitActionData submitActionData) : base(submitActionData)
{
}