Code cleanup

This commit is contained in:
2026-01-28 22:39:29 +01:00
parent fc8d59ae12
commit 0878d0885a
4 changed files with 10 additions and 19 deletions

View File

@@ -3,21 +3,14 @@ using Sandbox.Models.ViewModels;
namespace Sandbox.App.Services.AuthService;
public class AuthService : IAuthService
public class AuthService(HttpClient httpClient, AuthenticationStateProvider authenticationStateProvider)
: IAuthService
{
private readonly HttpClient _http;
//private readonly AuthenticationStateProvider _authenticationStateProvider;
// public AuthService(HttpClient httpClient, AuthenticationStateProvider authenticationStateProvider)
public AuthService(HttpClient httpClient)
{
_http = httpClient;
//_authenticationStateProvider = authenticationStateProvider;
}
private readonly AuthenticationStateProvider _authenticationStateProvider = authenticationStateProvider;
public async Task<ServiceResponse<int>> Register(UserRegister request)
{
var result = await _http.PostAsJsonAsync("api/auth/register", request);
var result = await httpClient.PostAsJsonAsync("api/auth/register", request);
return await result.Content.ReadFromJsonAsync<ServiceResponse<int>>();
}

View File

@@ -2,8 +2,6 @@
@using Sandbox.Models.ViewModels
@inject Sandbox.App.Services.AuthService.IAuthService AuthService
@* @inject AuthenticationStateProvider AuthenticationStateProvider *@
@* @inject NavigationManager NavigationManager *@
<title>Register</title>
@@ -52,8 +50,6 @@
@code {
[SupplyParameterFromForm] private UserRegister user { get; set; }
//HttpClient _http = new() { BaseAddress = new("https://localhost:7122") };
private string message = string.Empty;
private string messageCssClass = string.Empty;
private string errorMessage = string.Empty;
@@ -62,8 +58,6 @@
async Task HandleRegistration()
{
// var response = await _http.PostAsJsonAsync("/api/register", user);
// var result = await response.Content.ReadFromJsonAsync<ServiceResponse<int>>();
var result = await AuthService.Register(user);
message = result.Message;
messageCssClass = result.Success ? "text-success" : "text-danger";

View File

@@ -2,7 +2,12 @@
using Microsoft.AspNetCore.Hosting.Server.Features;
namespace Sandbox;
/// <summary>
/// Source: https://www.duracellko.net/posts/2020/06/hosting-both-blazor-server-and-webassembly
/// </summary>
/// <param name="httpClient"></param>
/// <param name="server"></param>
/// <param name="applicationLifetime"></param>
public class HttpClientSetupService(
HttpClient httpClient,
IServer server,

View File

@@ -3,7 +3,6 @@ using Sandbox.Components;
using Sandbox.Models.ViewModels;
using Sandbox.Services.AuthService;
using ClientServices = Sandbox.App.Services;
using ServerServices = Sandbox.Services;
var builder = WebApplication.CreateBuilder(args);