Wonky.Client/Wonky.Client/Program.cs
2022-06-27 08:48:25 +02:00

74 lines
3.2 KiB
C#

// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Options;
using Toolbelt.Blazor.Extensions.DependencyInjection;
using Blazored.LocalStorage;
using Blazored.Toast;
using Wonky.Client;
using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpRepository;
using Wonky.Client.Services;
using Wonky.Client.Shared;
using Wonky.Entity.Configuration;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
builder.Services.AddScoped(sp =>
sp.GetService<IHttpClientFactory>().CreateClient("InnoAPI"));
builder.Services.AddHttpClient("InnoAPI", (sp, cl) =>
{
var apiConfig = sp.GetRequiredService<IOptions<ApiConfig>>();
cl.BaseAddress = new Uri(apiConfig.Value.InnoBaseUrl);
cl.EnableIntercept(sp);
});
builder.Services.AddBlazoredToast();
builder.Services.AddHttpClientInterceptor();
builder.Services.Configure<ApiConfig>(builder.Configuration.GetSection("ApiConfig"));
builder.Services.Configure<AppInfo>(builder.Configuration.GetSection("AppInfo"));
builder.Services.AddScoped<ICompanyHttpRepository, CompanyHttpRepository>();
builder.Services.AddScoped<ISalesItemHttpRepository, SalesItemHttpRepository>();
builder.Services.AddScoped<IActivityHttpRepository, ActivityHttpRepository>();
builder.Services.AddScoped<IReportHttpRepository, ReportHttpRepository>();
builder.Services.AddScoped<ITaskItemHttpRepository, TaskItemHttpRepository>();
builder.Services.AddScoped<IHistoryHttpRepository, HistoryHttpRepository>();
builder.Services.AddScoped<IUserHttpRepository, UserHttpRepository>();
builder.Services.AddScoped<IAdminReportHttpRepository, AdminReportHttpRepository>();
builder.Services.AddScoped<HttpInterceptorService>();
builder.Services.AddBlazoredLocalStorage();
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<AuthenticationStateProvider, AuthStateProvider>();
builder.Services.AddScoped<IAuthenticationService, AuthenticationService>();
builder.Services.AddScoped<RefreshTokenService>();
builder.Services.AddScoped<VatInfoLookupService>();
builder.Services.AddScoped<UserPreferenceService>();
// ---------------------------------------
await builder.Build().RunAsync();