【发布时间】:2020-11-11 19:03:07
【问题描述】:
那么@using System.Net.Http 有什么不同;您在哪里创建对象并调用该方法@inject HttpClient Http 之间有什么不同所以我正在尝试学习 Blazor
有人能解释一下这个工作的区别吗
@using System.Net.Http;
@code {
private WeatherForecast[] forecasts;
protected override async Task OnInitializedAsync()
{
var Http = new HttpClient();
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}
或
@page "/fetchdata"
@inject HttpClient Http
@code {
private WeatherForecast[] forecasts;
protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}
【问题讨论】:
标签: c# dependency-injection blazor