travail sur l'api mais je suis un peu perdu dcp a revoir

blazor
Patrick BRUGIERE 1 year ago
parent ff6bda4f2a
commit 5f13f4aaff

@ -24,17 +24,17 @@ builder.Services.AddHttpClient("GitHub", httpClient =>
// The GitHub API requires two headers.
httpClient.DefaultRequestHeaders.Add(HeaderNames.Accept, "application/vnd.github.v3+json");
httpClient.DefaultRequestHeaders.Add(HeaderNames.UserAgent, "HttpRequestsSample");
});
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddScoped<IDataService, DataLocalService>();
<<<<<<< HEAD
builder.Services.AddScoped<IDataService, DataApiService>();
=======
builder.Services.AddScoped<IVocListService, VocListLocalService>();
//builder.Services.AddScoped<IDataService, DataApiService>();
>>>>>>> f62a4611bcbbfe0ed449a38e75f10df8ce6a5bbe
builder.Services.AddScoped<IVocListService, VocListLocalService>();
builder.Services.AddHttpClient();
builder.Services.AddBlazoredLocalStorage();

@ -8,12 +8,15 @@ namespace adminBlazor.Services
public class DataApiService : IDataService
{
private readonly HttpClient _http;
private readonly IHttpClientFactory _httpClientFactory;
public DataApiService(
HttpClient http)
public DataApiService(IHttpClientFactory httpClientFactory)
{
_http = http;
_httpClientFactory = httpClientFactory;
_http = _httpClientFactory.CreateClient("GitHub");
}
public async Task Add(UserModel model)
{
// Get the item
@ -35,9 +38,7 @@ namespace adminBlazor.Services
public async Task<User> GetById(int id)
{
if ( _http.GetFromJsonAsync<User>($"https://localhost:7234/api/Crafting/{id}") != null)
return await _http.GetFromJsonAsync<User>($"https://localhost:7234/api/Crafting/{id}");
else return null;
}
public async Task Update(int id, UserModel model)

@ -13,17 +13,22 @@ namespace adminBlazor.Services
private readonly ILocalStorageService _localStorage;
private readonly NavigationManager _navigationManager;
private readonly IWebHostEnvironment _webHostEnvironment;
private readonly IHttpClientFactory _httpClientFactory;
public DataLocalService(
ILocalStorageService localStorage,
HttpClient http,
IWebHostEnvironment webHostEnvironment,
NavigationManager navigationManager)
NavigationManager navigationManager,
IHttpClientFactory httpClientFactory)
{
_localStorage = localStorage;
_http = http;
//_http = http;
_webHostEnvironment = webHostEnvironment;
_navigationManager = navigationManager;
_httpClientFactory = httpClientFactory;
_http = httpClientFactory.CreateClient("GitHub");
}
public DataLocalService(ILocalStorageService localStorage)
{

Loading…
Cancel
Save