BlazorStart/Start/Client/Program.cs

55 lines
1.8 KiB
C#
Raw Normal View History

2021-11-13 03:21:59 +00:00
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Blazored.LocalStorage;
using Refit;
using Start.Shared.Api;
2021-12-04 00:44:02 +00:00
using Fluxor;
2021-11-13 03:21:59 +00:00
namespace Start.Client {
public class Program {
public static async Task Main(string[] args) {
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
2021-11-13 03:21:59 +00:00
builder.Services.AddHttpClient("Start.ServerAPI",
client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
2021-11-13 03:21:59 +00:00
// Supply HttpClient instances that include access tokens when making requests to the
// server project
builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>()
.CreateClient("Start.ServerAPI"));
2021-11-13 03:21:59 +00:00
// Blazor will throw an error if a relative URI is used, so we have to get the base
// address for building the API paths
Uri baseUri = new(builder.HostEnvironment.BaseAddress);
builder.Services.AddRefitClient<IBookmarkContainersApi>()
.ConfigureHttpClient(c => {
c.BaseAddress = new Uri(baseUri, "BookmarkContainers");
})
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
2021-11-13 03:21:59 +00:00
builder.Services.AddRefitClient<IBookmarksApi>()
.ConfigureHttpClient(c => { c.BaseAddress = new Uri(baseUri, "Bookmarks"); })
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
builder.Services.AddApiAuthorization();
builder.Services.AddBlazoredLocalStorage();
2021-12-04 00:44:02 +00:00
builder.Services.AddFluxor(opt => {
opt.ScanAssemblies(typeof(Program).Assembly);
#if DEBUG
opt.UseReduxDevTools();
#endif
});
await builder.Build().RunAsync();
}
}
2021-11-13 03:21:59 +00:00
}