Refactor Dependency Builder

This commit is contained in:
Daniel_I_Am 2021-01-02 12:19:22 +01:00
parent 7cab8dbac0
commit 28d7afa486
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84
2 changed files with 21 additions and 5 deletions

View File

@ -0,0 +1,19 @@
using ChaosBot.Discord.Services;
using Discord.Commands;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
namespace ChaosBot.Dependency
{
public static class ServiceBuilder
{
public static ServiceProvider Create()
{
return new ServiceCollection()
.AddSingleton<DiscordSocketClient>()
.AddSingleton<CommandService>()
.AddSingleton<CommandHandler>()
.BuildServiceProvider();
}
}
}

View File

@ -4,6 +4,7 @@ using Discord.Commands;
using Discord.WebSocket;
using System.Threading.Tasks;
using ChaosBot.ConfigHelpers;
using ChaosBot.Dependency;
using ChaosBot.Discord.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@ -62,11 +63,7 @@ namespace ChaosBot.Discord
try
{
csInfo = new ServiceCollection()
.AddSingleton<DiscordSocketClient>()
.AddSingleton<CommandService>()
.AddSingleton<CommandHandler>()
.BuildServiceProvider();
csInfo = ServiceBuilder.Create();
}
catch (Exception ex)
{