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
serviceProviderIServiceProviderloggerFactoryILoggerFactory
Methods
DisposeAsync
#public async ValueTask DisposeAsync();Disposes the underlying HTML renderer.
Returns
ValueTaskRenderComponentAsync<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
parametersIDictionary<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;
}