demo/Services/UserService.cs

27 lines
633 B
C#
Raw Permalink Normal View History

2024-06-21 16:48:24 +08:00
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using antblazorpro.Models;
namespace antblazorpro.Services
{
public interface IUserService
{
Task<CurrentUser> GetCurrentUserAsync();
}
public class UserService : IUserService
{
private readonly HttpClient _httpClient;
public UserService(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<CurrentUser> GetCurrentUserAsync()
{
return await _httpClient.GetFromJsonAsync<CurrentUser>("data/current_user.json");
}
}
}