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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-06-13 11:00:00 +0000
Seen: 10 times
Last updated: Mar 03 '22
What is the process for altering the primary color of Radzen in Blazor Web Assembly?
What is the method for uploading a file in Blazor WebAssembly which is hosted by aspnetcore?
How can the CheckBox checking capability be restricted in Blazor?
How do I create an index.html page for the js project in D3 JS?
Where can I find the location of the NuGet packages I have downloaded for my project?