code style cleanup

This commit is contained in:
Aaron Po
2026-06-20 13:55:17 -04:00
parent 07aedcb866
commit 254431928f
167 changed files with 3711 additions and 3522 deletions

View File

@@ -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;
}
}
}