Following the postal tutorial, If I change the enqueue call to pass a NewCommentEmail object, when the background job runs (and in the Hangfire Dashboard) the job does not seralize the passed argument.
Changed Enqueue line in the HomeController Create method:
var email = new NewCommentEmail
{
To = "yourmail@example.com",
UserName = model.UserName,
Comment = model.Text
};
_jobClient.Enqueue(() => SendEmail.SendWithFullObject(email));
The SendWithFullObject Method
public static void SendWithFullObject(NewCommentEmail email)
{
// Prepare Postal classes to work outside of ASP.NET request
var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
var engines = new ViewEngineCollection();
engines.Add(new FileSystemRazorViewEngine(viewsPath));
var emailService = new EmailService(engines);
email.To = "yourmail@example.com";
emailService.Send(email);
}
Example of job in the Hangfire Dashboard.
“Serialization/deserialization process is transparent. Just pass an instance:”
BackgroundJob.Enqueue(() => Console.WriteLine(new MySuperObject { Property1 = "Value1" }));"