Improved handling of email templates.
Almircar opened this issue · 0 comments
So as not to have all the handling of the email templates in the core.
You can create an interface .
public interface IEmailTemplateParser<T>
{
string PrepareEmail(T data , string stringTemplate);
}
Classes that handle email templates would implement that interface and by convention the class name should end in "TemplateParser"
Modify the appsettings.json section as follows.
"EmailTemplateSettings":
[
{
"Name": "ActivateNewUser",
"TemplateName": "activate-new-user-template.html",
"Subject": "XXXXXXX"
},
{
"Name": "ResetPassword",
"TemplateName": "reset-password-template.html",
"Subject": "YYYYYYYYY"
}
]
Modify the way to load the Options as follows.
services.Configure<List>
When you need to obtain the values a specific template, you look for it like this.
var templateInfo = emailTemplateSettings.Find(x => x.Name.Contains("ActivateNewUser"));
var core = System.Reflection.Assembly.GetExecutingAssembly();
builder.RegisterAssemblyTypes(core)
.Where(t => t.Name.EndsWith("TemplateParser"))
.AsImplementedInterfaces();
To record the types, include this in the module.
I hope my idea seems good to you and I apologize for the terrible English.