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

Simplify API #18

Merged
merged 21 commits into from
Mar 22, 2024
Merged

Simplify API #18

merged 21 commits into from
Mar 22, 2024

Conversation

hbulens
Copy link
Member

@hbulens hbulens commented Mar 13, 2024

Merged similar classes with similar purposes and simplified the configuration. AddFacteur is the entry point and exposes an instance of the FacteurBuilder class.

serviceCollection.AddFacteur(x =>
{
    x.WithMailer(y => new SmtpMailer(credentials, y.GetService<IEmailComposer>()))
    .WithCompiler<ScribanCompiler>()
    .WithTemplateProvider(x => new AppDirectoryTemplateProvider("Templates", ".sbnhtml"))
    .WithResolver<ViewModelTemplateResolver>()
    .WithDefaultComposer();
});

For simple email workflows, no compilers, providers, resolvers or composers are required. To use the templating system and dynamic content, correct DI configuration enables the use of a new overload in the IMailer:

public async Task SendConfirmationMail(string customerMail, string customerName)
{
  await mailer.SendMailAsync(x =>  x      
      .SetSubject("Hello world")
      .SetFrom("[email protected]")
      .SetTo("[email protected]")
      .SetCc("[email protected]")
      .SetBcc("[email protected]")
      .BuildAsync(new TestMailModel { Email = customerMail, Name = customerMail }));
}

This overload exposes the composer and will build the request before sending it out. That way you don't need to resolve and instantiate an instance of the IEmailComposer class anymore, even though that's still a possibility.

@hbulens hbulens merged commit a7dc0b5 into master Mar 22, 2024
2 checks passed
@hbulens hbulens deleted the fluent-api-di branch March 22, 2024 07:21
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

Successfully merging this pull request may close these issues.

1 participant