mirror of
https://github.com/FalloutCollaborationProject/FCP-Mod-Updater.git
synced 2026-07-27 17:04:05 -07:00
Add Dependency Injection for Future Updates
This commit is contained in:
+24
-2
@@ -1,10 +1,22 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Runtime.InteropServices;
|
||||
using FCPModUpdater;
|
||||
using FCPModUpdater.Commands;
|
||||
using FCPModUpdater.Infrastructure;
|
||||
using FCPModUpdater.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
var app = new CommandApp();
|
||||
var services = new ServiceCollection();
|
||||
|
||||
services.AddHttpClient<IGitHubApiService, GitHubApiService>(ConfigureGitHubClient);
|
||||
services.AddHttpClient<UpdateCheckService>(ConfigureGitHubClient);
|
||||
|
||||
services.AddSingleton<IGitService, GitService>();
|
||||
services.AddSingleton<IModDiscoveryService, ModDiscoveryService>();
|
||||
|
||||
var app = new CommandApp(new TypeRegistrar(services));
|
||||
|
||||
app.Configure(config =>
|
||||
{
|
||||
@@ -21,7 +33,6 @@ app.Configure(config =>
|
||||
.WithDescription("Update all FCP mods (non-interactive)")
|
||||
.WithExample("update")
|
||||
.WithExample("update", "--directory", "/path/to/RimWorld/Mods");
|
||||
|
||||
});
|
||||
|
||||
app.SetDefaultCommand<ScanCommand>();
|
||||
@@ -37,3 +48,14 @@ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
void ConfigureGitHubClient(HttpClient client)
|
||||
{
|
||||
client.BaseAddress = new Uri("https://api.github.com");
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd($"FCPModUpdater/{AppVersion.SemanticVersion}");
|
||||
client.DefaultRequestHeaders.Accept.ParseAdd("application/vnd.github+json");
|
||||
|
||||
var token = Environment.GetEnvironmentVariable("GITHUB_TOKEN");
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user