hn-dotnet/Apps/Client/Program.cs

43 lines
1.2 KiB
C#

using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Components.Authorization;
namespace Client
{
public class MyState
{
public List<string> Names { get; } = new List<string>();
public event Action OnChange;
public void AddName(string name)
{
Names.Add(name);
OnChange?.Invoke();
}
}
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:8888/") });
builder.Services.AddScoped<LinksClient>();
builder.Services.AddScoped<AccountsClient>();
builder.Services.AddSingleton<MyState>();
builder.Services.AddSingleton<NotificationManager>();
builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthStateProvider>();
await builder.Build().RunAsync();
}
}
}