chaosbot/ChaosBot/Dependency.cs

29 lines
769 B
C#

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)}");
}
}
}