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