mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-06-06 09:31:16 -04:00
[CLI] Use Microsoft.Extensions.DependencyInjection instead of Stylet
This commit is contained in:
parent
5e0a2c6761
commit
9299b95250
2 changed files with 23 additions and 14 deletions
|
@ -10,8 +10,8 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CliFx" Version="0.0.5" />
|
<PackageReference Include="CliFx" Version="0.0.7" />
|
||||||
<PackageReference Include="Stylet" Version="1.3.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
|
||||||
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.3" />
|
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -1,33 +1,42 @@
|
||||||
using System.Threading.Tasks;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using CliFx;
|
using CliFx;
|
||||||
|
using DiscordChatExporter.Cli.Commands;
|
||||||
using DiscordChatExporter.Core.Services;
|
using DiscordChatExporter.Core.Services;
|
||||||
using StyletIoC;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli
|
namespace DiscordChatExporter.Cli
|
||||||
{
|
{
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
private static IContainer BuildContainer()
|
private static IServiceProvider ConfigureServices()
|
||||||
{
|
{
|
||||||
var builder = new StyletIoCBuilder();
|
var services = new ServiceCollection();
|
||||||
|
|
||||||
// Autobind the .Services assembly
|
// Register services
|
||||||
builder.Autobind(typeof(DataService).Assembly);
|
services.AddSingleton<DataService>();
|
||||||
|
services.AddSingleton<ExportService>();
|
||||||
|
services.AddSingleton<SettingsService>();
|
||||||
|
|
||||||
// Bind settings as singleton
|
// Register commands
|
||||||
builder.Bind<SettingsService>().ToSelf().InSingletonScope();
|
services.AddTransient<ExportChannelCommand>();
|
||||||
|
services.AddTransient<ExportDirectMessagesCommand>();
|
||||||
|
services.AddTransient<ExportGuildCommand>();
|
||||||
|
services.AddTransient<GetChannelsCommand>();
|
||||||
|
services.AddTransient<GetDirectMessageChannelsCommand>();
|
||||||
|
services.AddTransient<GetGuildsCommand>();
|
||||||
|
services.AddTransient<GuideCommand>();
|
||||||
|
|
||||||
// Set instance
|
return services.BuildServiceProvider();
|
||||||
return builder.BuildContainer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<int> Main(string[] args)
|
public static Task<int> Main(string[] args)
|
||||||
{
|
{
|
||||||
var container = BuildContainer();
|
var serviceProvider = ConfigureServices();
|
||||||
|
|
||||||
return new CliApplicationBuilder()
|
return new CliApplicationBuilder()
|
||||||
.AddCommandsFromThisAssembly()
|
.AddCommandsFromThisAssembly()
|
||||||
.UseCommandFactory(schema => (ICommand) container.Get(schema.Type))
|
.UseCommandFactory(schema => (ICommand) serviceProvider.GetService(schema.Type))
|
||||||
.Build()
|
.Build()
|
||||||
.RunAsync(args);
|
.RunAsync(args);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue