Skip to content

Improved handling of email templates. #2

@Almircar

Description

@Almircar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions