1 | initial version |
Here are the steps to incorporate Blazor Web Assembly into your .Net Core 6 project through injection:
dotnet new blazorwasm
.In the Startup.cs class of your .Net Core 6 project, add the following code to the ConfigureServices method:
services.AddHttpClient();
services.AddBlazor();
In any class or component where you want to use Blazor Web Assembly, inject the IHttpClientFactory and IJSRuntime services as follows:
using Microsoft.AspNetCore.Components.WebAssembly.Services;
using System.Net.Http;
public class MyComponent : ComponentBase
{
[Inject]
private IHttpClientFactory HttpClientFactory { get; set; }
[Inject]
private IJSRuntime JSRuntime { get; set; }
}
You can now use Blazor Web Assembly and all its features in your .Net Core 6 project through injection.