using Microsoft.Extensions.Configuration;

namespace Knoks.Framework.Extentions
{
    public static class ConfigurationExtensions
    {
        public static T Load<T>(this IConfiguration config) where T : new()
        {
            return config.Load(typeof(T).Name, new T());
        }

        public static T Load<T>(this IConfiguration config, string key) where T : new()
        {
            return config.Load(key, new T());
        }

        public static T Load<T>(this IConfiguration config, T instance)
        {
            return config.Load(typeof(T).Name, instance);
        }

        public static T Load<T>(this IConfiguration config, string key, T instance)
        {
            config.GetSection(key).Bind(instance);
            return instance;
        }
    }
}