From 28d7afa4864873dcea9fe64d4975668fa1808cda Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Sat, 2 Jan 2021 12:19:22 +0100 Subject: [PATCH] Refactor Dependency Builder --- ChaosBot/Dependency/ServiceBuilder.cs | 19 +++++++++++++++++++ ChaosBot/Discord/DiscordConnect.cs | 7 ++----- 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 ChaosBot/Dependency/ServiceBuilder.cs diff --git a/ChaosBot/Dependency/ServiceBuilder.cs b/ChaosBot/Dependency/ServiceBuilder.cs new file mode 100644 index 0000000..6200f97 --- /dev/null +++ b/ChaosBot/Dependency/ServiceBuilder.cs @@ -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() + .AddSingleton() + .AddSingleton() + .BuildServiceProvider(); + } + } +} diff --git a/ChaosBot/Discord/DiscordConnect.cs b/ChaosBot/Discord/DiscordConnect.cs index 878db02..3c9a2f2 100644 --- a/ChaosBot/Discord/DiscordConnect.cs +++ b/ChaosBot/Discord/DiscordConnect.cs @@ -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() - .AddSingleton() - .AddSingleton() - .BuildServiceProvider(); + csInfo = ServiceBuilder.Create(); } catch (Exception ex) {