Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved handling of email templates. #2

Open
Almircar opened this issue Mar 28, 2020 · 0 comments
Open

Improved handling of email templates. #2

Almircar opened this issue Mar 28, 2020 · 0 comments

Comments

@Almircar
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant