This site provides a machine-readable index at /llms.txt.

Skip to main content Skip to navigation

ComponentRenderer Pennington.Islands

Renders Blazor components to HTML strings using static HtmlRenderer. Registered as Scoped — shared across a request, disposed at scope end.

Constructors

.ctor

#
public sealed class ComponentRenderer(
    IServiceProvider serviceProvider,
    ILoggerFactory loggerFactory) : IAsyncDisposable
{
    private readonly HtmlRenderer _renderer = new(serviceProvider, loggerFactory);

    /// <summary>Renders a Blazor component to an HTML string with the given parameters.</summary>
    public Task<string> RenderComponentAsync<TComponent>(
        IDictionary<string, object?>? parameters = null)
        where TComponent : IComponent
    {
        return _renderer.Dispatcher.InvokeAsync(async () =>
        {
            var pv = parameters is not null
                ? ParameterView.FromDictionary(parameters)
                : ParameterView.Empty;

            var output = await _renderer.RenderComponentAsync<TComponent>(pv);
            return output.ToHtmlString();
        });
    }

    /// <summary>Disposes the underlying HTML renderer.</summary>
    public async ValueTask DisposeAsync()
    {
        await _renderer.DisposeAsync();
    }
}

Renders Blazor components to HTML strings using static HtmlRenderer. Registered as Scoped — shared across a request, disposed at scope end.

Parameters

serviceProvider IServiceProvider
loggerFactory ILoggerFactory

Methods

DisposeAsync

#
public async ValueTask DisposeAsync();

Disposes the underlying HTML renderer.

Returns

ValueTask

RenderComponentAsync<TComponent>

#
public Task<string> RenderComponentAsync<TComponent>(
    IDictionary<string, object?>? parameters = null)
    where TComponent : IComponent;

Renders a Blazor component to an HTML string with the given parameters.

Parameters

parameters IDictionary<string, object?>? (optional)

Returns

Task<string>

Pennington.Islands.ComponentRenderer

namespace Pennington.Islands;

/// Renders Blazor components to HTML strings using static HtmlRenderer. Registered as Scoped — shared across a request, disposed at scope end.
public class ComponentRenderer
{
    /// Renders Blazor components to HTML strings using static HtmlRenderer. Registered as Scoped — shared across a request, disposed at scope end.
    
public sealed class ComponentRenderer(
    IServiceProvider serviceProvider,
    ILoggerFactory loggerFactory) : IAsyncDisposable
{
    private readonly HtmlRenderer _renderer = new(serviceProvider, loggerFactory);

    /// <summary>Renders a Blazor component to an HTML string with the given parameters.</summary>
    public Task<string> RenderComponentAsync<TComponent>(
        IDictionary<string, object?>? parameters = null)
        where TComponent : IComponent
    {
        return _renderer.Dispatcher.InvokeAsync(async () =>
        {
            var pv = parameters is not null
                ? ParameterView.FromDictionary(parameters)
                : ParameterView.Empty;

            var output = await _renderer.RenderComponentAsync<TComponent>(pv);
            return output.ToHtmlString();
        });
    }

    /// <summary>Disposes the underlying HTML renderer.</summary>
    public async ValueTask DisposeAsync()
    {
        await _renderer.DisposeAsync();
    }
}
/// Disposes the underlying HTML renderer.
public async ValueTask DisposeAsync();
/// Renders a Blazor component to an HTML string with the given parameters.
public Task<string> RenderComponentAsync<TComponent>(
    IDictionary<string, object?>? parameters = null)
    where TComponent : IComponent;
}