MVFC.RazorRender
1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package MVFC.RazorRender --version 1.0.1
NuGet\Install-Package MVFC.RazorRender -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MVFC.RazorRender" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MVFC.RazorRender" Version="1.0.1" />
<PackageReference Include="MVFC.RazorRender" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MVFC.RazorRender --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MVFC.RazorRender, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MVFC.RazorRender@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MVFC.RazorRender&version=1.0.1
#tool nuget:?package=MVFC.RazorRender&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MVFC.RazorRender
Biblioteca para renderização de componentes Razor em HTML, com suporte a cache híbrido e integração facilitada via Dependency Injection (DI). Permite transformar componentes Blazor em HTML para cenários como geração de e-mails, relatórios ou exportação de conteúdo dinâmico.
Observação:
- Para que a renderização de componentes Razor funcione corretamente, é necessário que o seu projeto com os arquivos razor inclua o arquivo
.Razorno seu.csproj.
Exemplo:
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
...
</Project>
Funcionalidades
- Renderização de componentes Razor/Blazor em HTML puro
- Suporte a cache híbrido para otimizar performance
- Integração simples com DI do .NET
- Ideal para geração de e-mails, relatórios, exportação de conteúdo, etc.
Instalação
Via NuGet:
Install-Package MVFC.RazorRender
Ou via .NET CLI:
dotnet add package MVFC.RazorRender
Como Usar
1. Configuração dos Serviços
No seu Program.cs ou durante a configuração de serviços:
Sem Cache
services.AddRazorRender();
Com Cache
services.AddRazorRenderCache(options =>
{
options.DefaultEntryOptions = new HybridCacheEntryOptions
{
Expiration = TimeSpan.FromMinutes(5)
};
});
2. Exemplo de DTO, Modelos e View
// DTO de parâmetro para renderização com cache
public sealed record CommentParameterDto(Post Model, string CacheKey) : IRazorCacheParameter;
// Modelos
public sealed record Post(int Id, string Title, string Content, IReadOnlyList<Comment> Comments);
public sealed record Comment(string Name, int Age);
// View Razor
public partial class BlogView : ComponentBase
{
[Parameter]
public required Post Model { get; set; }
}
3. Injeção de dependência
public sealed class SeuServico(
IRazorHtmlRenderService razorRenderService, // Serviço sem cache
ICacheRazorHtmlRenderService cacheRazorHtmlRender) // Serviço com cache
{
private readonly IRazorHtmlRenderService _razorRenderService = razorRenderService;
private readonly ICacheRazorHtmlRenderService _cacheRazorHtmlRender = cacheRazorHtmlRender;
...
...
}
4. Renderizando um Componente Razor
var model = MockFactory.CreatePostMock();
var parameters = new CommentParameterDto(Model: model, CacheKey: "test");
// Renderização sem cache
string html = await _razorRenderService.GenerateHtmlAsync<BlogView>(parameters);
// Renderização com cache
string htmlCache = await _cacheRazorHtmlRender.GenerateHtmlAsync<BlogView>(parameters);
5. Exemplo de Teste Automatizado
[Fact(DisplayName = "Renderização Razor HTML de Post")]
public async Task Test_Post_RazorHtmlRender()
{
var model = MockFactory.CreatePostMock();
var parameters = new CommentParameterDto(Model: model, CacheKey: "test");
string html = await _razorRenderService.GenerateHtmlAsync<BlogView>(parameters);
Assert.NotNull(html);
}
Principais Interfaces
IRazorHtmlRenderService: Renderização Razor sem cacheICacheRazorHtmlRenderService: Renderização Razor com cache híbridoIRazorParametereIRazorCacheParameter: Parâmetros para renderização
Licença
Este projeto está licenciado sob a licença Apache-2.0.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.AspNetCore.Components.Web (>= 9.0.11)
- Microsoft.Extensions.Caching.Hybrid (>= 10.0.0)
- Microsoft.Extensions.Logging (>= 9.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.