I have an existing project, and I want to add Blazor to my project, but in all the information available on the internet, I have not found how to do that. All I find is about how to add js to blazor pages.
1 Answer
Let's assume that your application want to use client-side Blazor, which would be simplest form to integrate. Also I will assume that you use ASP.NET Core for simplification.
- You create Blazor client-side application. This application would be completely standalone and in the end would be just WASM code + .NET Dlls interpreted by Mono WASM.
- In the
ConfigureServicesof your Startup.cs in ASP.NET Core application where you want integrate Blazor add lines below
services.AddResponseCompression(opts =>
{
opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { "application/octet-stream" });
});
- In the
Configureof your Startup.cs in ASP.NET Core application where you want integrate Blazor add lines below
app.UseBlazor<BlazorAppClient.Startup>();
where BlazorAppClient.Startup is Startup class of your Blazor standalone application which you create earlier.
See https://github.com/aspnet/AspNetCore/blob/master/src/Components/Blazor/Templates/src/content/BlazorHosted-CSharp/BlazorHosted-CSharp.Server/Startup.cs#L43
All of that under assumption that you use latest .NET Core 3 Preview 5 bits.