Remove dependency injector
This commit is contained in:
parent
eb2a80e65d
commit
b766813b60
@ -10,7 +10,7 @@ namespace ChaosBot.Attribute
|
||||
{
|
||||
public static class AssemblyController
|
||||
{
|
||||
private static ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static ILogger _logger = Program.Logger;
|
||||
public static void RegisterAll()
|
||||
{
|
||||
Assembly dbEntityAssembly = Assembly.GetAssembly(typeof(DBEntity));
|
||||
|
||||
@ -13,7 +13,7 @@ namespace ChaosBot.Database
|
||||
public static class Controller
|
||||
{
|
||||
static SqliteConnection _conn = new SqliteConnection($"Data Source={System.IO.Directory.GetCurrentDirectory()}/{ConfigurationRepository.GetValue<string>("Bot:Database")}");
|
||||
private static ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static ILogger _logger = Program.Logger;
|
||||
|
||||
/// <summary>
|
||||
/// Run a raw query on the database
|
||||
|
||||
@ -9,7 +9,7 @@ namespace ChaosBot.Database.Repository
|
||||
{
|
||||
public static class ConfigurationRepository
|
||||
{
|
||||
private static ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static ILogger _logger = Program.Logger;
|
||||
public static IConfiguration AppSettingsHandler { get; set; }
|
||||
|
||||
private static readonly string ServersTable = "ServerConfigurationFlags";
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
|
||||
namespace ChaosBot
|
||||
{
|
||||
public static class Dependency
|
||||
{
|
||||
private static Dictionary<Type, object> InstanceList;
|
||||
|
||||
public static void Initialize(IConfiguration appSettingsHandler)
|
||||
{
|
||||
InstanceList = new Dictionary<Type, object>
|
||||
{
|
||||
{typeof(ILogger), Logging.GenLog(appSettingsHandler)}
|
||||
};
|
||||
}
|
||||
|
||||
public static T GetInstance<T>()
|
||||
{
|
||||
if (InstanceList.TryGetValue(typeof(T), out object obj))
|
||||
{
|
||||
return (T) obj;
|
||||
}
|
||||
throw new KeyNotFoundException($"Could not find dependency of type {typeof(T)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,7 +15,7 @@ namespace ChaosBot.Discord
|
||||
public class DiscordConnect
|
||||
{
|
||||
private static DiscordSocketClient _client;
|
||||
private static ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static ILogger _logger = Program.Logger;
|
||||
|
||||
public static async Task StartUp()
|
||||
{
|
||||
|
||||
@ -11,7 +11,7 @@ namespace ChaosBot.Discord.Modules
|
||||
{
|
||||
public class AdminCommands : ModuleBase
|
||||
{
|
||||
private static readonly ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static readonly ILogger _logger = Program.Logger;
|
||||
|
||||
|
||||
[Command("clear")]
|
||||
|
||||
@ -11,7 +11,7 @@ namespace ChaosBot.Discord.Modules
|
||||
{
|
||||
public class ConfigCommands : ModuleBase
|
||||
{
|
||||
private static readonly ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static readonly ILogger _logger = Program.Logger;
|
||||
private static readonly string _prefix = ConfigurationRepository.GetValue<string>("Discord:Prefix");
|
||||
|
||||
[Command("config")]
|
||||
|
||||
@ -12,7 +12,7 @@ namespace ChaosBot.Discord.Modules
|
||||
{
|
||||
public class DiceCommands : ModuleBase
|
||||
{
|
||||
private static ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static ILogger _logger = Program.Logger;
|
||||
|
||||
[Command("roll")]
|
||||
public async Task Roll(params string[] args)
|
||||
|
||||
@ -12,7 +12,7 @@ namespace ChaosBot.Discord.Modules
|
||||
{
|
||||
public class InfoCommands : ModuleBase
|
||||
{
|
||||
private static readonly ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static readonly ILogger _logger = Program.Logger;
|
||||
|
||||
|
||||
[Command("info")]
|
||||
|
||||
@ -17,7 +17,7 @@ namespace ChaosBot.Discord.Modules
|
||||
{
|
||||
public class LodestoneCommands : ModuleBase
|
||||
{
|
||||
private static readonly ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static readonly ILogger _logger = Program.Logger;
|
||||
|
||||
|
||||
[Command("lodestone character")]
|
||||
|
||||
@ -15,7 +15,7 @@ namespace ChaosBot.Discord.Modules
|
||||
{
|
||||
public class PointsCommands : ModuleBase
|
||||
{
|
||||
private static ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static ILogger _logger = Program.Logger;
|
||||
|
||||
[Command("points help")]
|
||||
public async Task PointsCommandInfo()
|
||||
|
||||
@ -13,7 +13,7 @@ namespace ChaosBot.Discord.Modules
|
||||
|
||||
public class RaffleSystem : ModuleBase
|
||||
{
|
||||
private static ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static ILogger _logger = Program.Logger;
|
||||
|
||||
[Command("raffle")]
|
||||
public async Task RaffleStatus()
|
||||
|
||||
@ -10,7 +10,7 @@ namespace ChaosBot.Discord.PreConditions
|
||||
{
|
||||
public class CheckCommandPerm : PreconditionAttribute
|
||||
{
|
||||
private static ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static ILogger _logger = Program.Logger;
|
||||
|
||||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
|
||||
{
|
||||
|
||||
@ -16,7 +16,7 @@ namespace ChaosBot.Discord.Services
|
||||
private readonly CommandService _commands;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private readonly ILogger _logger = Program.Logger;
|
||||
|
||||
public CommandHandler(IServiceProvider services)
|
||||
{
|
||||
|
||||
@ -12,7 +12,7 @@ namespace ChaosBot.Discord.Services
|
||||
{
|
||||
public static class TimerHandler
|
||||
{
|
||||
private static readonly ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static readonly ILogger _logger = Program.Logger;
|
||||
private static DiscordSocketClient _client;
|
||||
|
||||
public static void Initialize(IServiceProvider services)
|
||||
|
||||
@ -12,7 +12,7 @@ namespace ChaosBot
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
private ILogger _logger;
|
||||
public static ILogger Logger;
|
||||
private static string _appsettingsPath;
|
||||
|
||||
private static void Main(string[] args)
|
||||
@ -29,21 +29,16 @@ namespace ChaosBot
|
||||
* Load configuration from AppSettings.Json and save as Cfg
|
||||
*/
|
||||
IConfiguration configurationHandler = LoadConfiguration(_appsettingsPath);
|
||||
|
||||
|
||||
/*
|
||||
* Initialize dependency injector
|
||||
* Initialize the _logger for logging purposes
|
||||
*/
|
||||
Dependency.Initialize(configurationHandler);
|
||||
Logger = Logging.GenLog(configurationHandler);
|
||||
|
||||
/*
|
||||
* Set AppSettingsHandler on ConfigurationRepository
|
||||
*/
|
||||
ConfigurationRepository.AppSettingsHandler = configurationHandler;
|
||||
|
||||
/*
|
||||
* Initialize the _logger for logging purposes
|
||||
*/
|
||||
_logger = Dependency.GetInstance<ILogger>();
|
||||
|
||||
/*
|
||||
* Attempt to load our custom assemblies
|
||||
@ -53,7 +48,7 @@ namespace ChaosBot
|
||||
/*
|
||||
* Initialize the Discord Client and Login
|
||||
*/
|
||||
_logger.Info($"Starting Up {ConfigurationRepository.GetValue<string>("Bot:Name")} v{ConfigurationRepository.GetValue<string>("Bot:Version")}");
|
||||
Logger.Info($"Starting Up {ConfigurationRepository.GetValue<string>("Bot:Name")} v{ConfigurationRepository.GetValue<string>("Bot:Version")}");
|
||||
|
||||
|
||||
var discordBot = LoadDiscord();
|
||||
@ -62,7 +57,7 @@ namespace ChaosBot
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, $"Program.MainFunction: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||
Logger.Error(ex, $"Program.MainFunction: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ namespace ChaosBot.Services
|
||||
|
||||
static class LodestoneHttpConnection
|
||||
{
|
||||
private static readonly ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private static readonly ILogger _logger = Program.Logger;
|
||||
static HttpClient client = new HttpClient();
|
||||
private static bool _firstRun = true;
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ namespace ChaosBot.WebServer.App.Controller
|
||||
[Route("/config/{guildId}/{flag}")]
|
||||
public class ConfigurationController
|
||||
{
|
||||
private readonly ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private readonly ILogger _logger = Program.Logger;
|
||||
|
||||
[HttpGet]
|
||||
public string GetConfigurationFlag(long guildId, string flag)
|
||||
|
||||
@ -10,7 +10,7 @@ namespace ChaosBot.WebServer
|
||||
{
|
||||
class Startup
|
||||
{
|
||||
private readonly ILogger _logger = Dependency.GetInstance<ILogger>();
|
||||
private readonly ILogger _logger = Program.Logger;
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user