2026-10-15 01:14:44 +02:00
|
|
|
using MeWeb.App.ViewModels;
|
2026-10-15 04:39:03 +02:00
|
|
|
using MeWeb.Core.Checks;
|
|
|
|
|
using MeWeb.Core.History;
|
|
|
|
|
using MeWeb.Core.Knowledge;
|
|
|
|
|
using MeWeb.Core.Net;
|
2026-10-15 01:14:44 +02:00
|
|
|
using MeWeb.Shared;
|
|
|
|
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
namespace MeWeb.App;
|
|
|
|
|
|
|
|
|
|
public static class AppServices
|
|
|
|
|
{
|
2026-10-15 04:39:03 +02:00
|
|
|
public const string Secure = "secure";
|
|
|
|
|
public const string Plain = "plain";
|
|
|
|
|
|
|
|
|
|
public static IServiceCollection AddMeWebApp(this IServiceCollection services, IPlatform platform)
|
2026-10-15 01:14:44 +02:00
|
|
|
{
|
2026-10-15 04:39:03 +02:00
|
|
|
var agent = $"me-web/{BuildInfo.Version}";
|
|
|
|
|
services.AddHttpClient(Secure, http => http.DefaultRequestHeaders.UserAgent.ParseAdd(agent));
|
|
|
|
|
services.AddHttpClient(Plain, http => http.DefaultRequestHeaders.UserAgent.ParseAdd(agent))
|
|
|
|
|
.ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler { AllowAutoRedirect = false });
|
|
|
|
|
services.AddSingleton(platform);
|
|
|
|
|
services.AddSingleton(sp =>
|
2026-10-15 01:14:44 +02:00
|
|
|
{
|
2026-10-15 04:39:03 +02:00
|
|
|
var factory = sp.GetRequiredService<IHttpClientFactory>();
|
|
|
|
|
return new ServerProbe(factory.CreateClient(Secure), factory.CreateClient(Plain));
|
2026-10-15 01:14:44 +02:00
|
|
|
});
|
2026-10-15 04:39:03 +02:00
|
|
|
services.AddSingleton<KnowledgeBase>();
|
|
|
|
|
services.AddSingleton(new HistoryStore(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MeWeb")));
|
|
|
|
|
services.AddSingleton<CheckRunner>();
|
2026-10-15 01:14:44 +02:00
|
|
|
services.AddTransient<MainViewModel>();
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|