mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-07-16 17:47:22 +00:00
code style cleanup
This commit is contained in:
@@ -1,22 +1,26 @@
|
||||
using Infrastructure.Email.Templates.Mail;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.Components.Web.HtmlRendering;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Infrastructure.Email.Templates.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// Service for rendering Razor email templates to HTML using HtmlRenderer.
|
||||
/// Service for rendering Razor email templates to HTML using HtmlRenderer.
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider">The service provider used to resolve dependencies for the Razor component rendering pipeline.</param>
|
||||
/// <param name="loggerFactory">The logger factory passed to the <see cref="HtmlRenderer"/> used to render components.</param>
|
||||
/// <param name="serviceProvider">
|
||||
/// The service provider used to resolve dependencies for the Razor component rendering
|
||||
/// pipeline.
|
||||
/// </param>
|
||||
/// <param name="loggerFactory">The logger factory passed to the <see cref="HtmlRenderer" /> used to render components.</param>
|
||||
public class EmailTemplateProvider(
|
||||
IServiceProvider serviceProvider,
|
||||
ILoggerFactory loggerFactory
|
||||
) : IEmailTemplateProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Renders the UserRegisteredEmail template with the specified parameters.
|
||||
/// Renders the UserRegisteredEmail template with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="username">The username to include in the email</param>
|
||||
/// <param name="confirmationLink">The email confirmation link</param>
|
||||
@@ -26,17 +30,17 @@ public class EmailTemplateProvider(
|
||||
string confirmationLink
|
||||
)
|
||||
{
|
||||
var parameters = new Dictionary<string, object?>
|
||||
Dictionary<string, object?> parameters = new()
|
||||
{
|
||||
{ nameof(UserRegistration.Username), username },
|
||||
{ nameof(UserRegistration.ConfirmationLink), confirmationLink },
|
||||
{ nameof(UserRegistration.ConfirmationLink), confirmationLink }
|
||||
};
|
||||
|
||||
return await RenderComponentAsync<UserRegistration>(parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the ResendConfirmation template with the specified parameters.
|
||||
/// Renders the ResendConfirmation template with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="username">The username to include in the email</param>
|
||||
/// <param name="confirmationLink">The new confirmation link</param>
|
||||
@@ -46,19 +50,19 @@ public class EmailTemplateProvider(
|
||||
string confirmationLink
|
||||
)
|
||||
{
|
||||
var parameters = new Dictionary<string, object?>
|
||||
Dictionary<string, object?> parameters = new()
|
||||
{
|
||||
{ nameof(ResendConfirmation.Username), username },
|
||||
{ nameof(ResendConfirmation.ConfirmationLink), confirmationLink },
|
||||
{ nameof(ResendConfirmation.ConfirmationLink), confirmationLink }
|
||||
};
|
||||
|
||||
return await RenderComponentAsync<ResendConfirmation>(parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generic method to render any Razor component to HTML.
|
||||
/// Creates a scoped <see cref="HtmlRenderer"/>, dispatches the render onto its renderer thread,
|
||||
/// and returns the resulting HTML string.
|
||||
/// Generic method to render any Razor component to HTML.
|
||||
/// Creates a scoped <see cref="HtmlRenderer" />, dispatches the render onto its renderer thread,
|
||||
/// and returns the resulting HTML string.
|
||||
/// </summary>
|
||||
/// <typeparam name="TComponent">The type of the Razor component to render.</typeparam>
|
||||
/// <param name="parameters">A dictionary of parameter names and values to pass to the component.</param>
|
||||
@@ -68,15 +72,15 @@ public class EmailTemplateProvider(
|
||||
)
|
||||
where TComponent : IComponent
|
||||
{
|
||||
await using var htmlRenderer = new HtmlRenderer(
|
||||
await using HtmlRenderer htmlRenderer = new(
|
||||
serviceProvider,
|
||||
loggerFactory
|
||||
);
|
||||
|
||||
var html = await htmlRenderer.Dispatcher.InvokeAsync(async () =>
|
||||
string html = await htmlRenderer.Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
var parameterView = ParameterView.FromDictionary(parameters);
|
||||
var output = await htmlRenderer.RenderComponentAsync<TComponent>(
|
||||
ParameterView parameterView = ParameterView.FromDictionary(parameters);
|
||||
HtmlRootComponent output = await htmlRenderer.RenderComponentAsync<TComponent>(
|
||||
parameterView
|
||||
);
|
||||
|
||||
@@ -85,4 +89,4 @@ public class EmailTemplateProvider(
|
||||
|
||||
return html;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
namespace Infrastructure.Email.Templates.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// Service for rendering Razor email templates to HTML.
|
||||
/// Service for rendering Razor email templates to HTML.
|
||||
/// </summary>
|
||||
public interface IEmailTemplateProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Renders the UserRegisteredEmail template with the specified parameters.
|
||||
/// Renders the UserRegisteredEmail template with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="username">The username to include in the email</param>
|
||||
/// <param name="confirmationLink">The email confirmation link</param>
|
||||
@@ -17,7 +17,7 @@ public interface IEmailTemplateProvider
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Renders the ResendConfirmation template with the specified parameters.
|
||||
/// Renders the ResendConfirmation template with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="username">The username to include in the email</param>
|
||||
/// <param name="confirmationLink">The new confirmation link</param>
|
||||
@@ -26,4 +26,4 @@ public interface IEmailTemplateProvider
|
||||
string username,
|
||||
string confirmationLink
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user