#region Apache License Version 2.0

#endregion Apache License Version 2.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using Microsoft.Extensions.DependencyInjection;
using SF.Sys.Linq;
using Microsoft.Extensions.Configuration;
using System.IO;
using SF.Sys.Hosting;

namespace SF.Sys.Services
{
	public static class MSConfigrationExtension
	{
		public class Configuration : Settings.IConfiguration
		{
			public IConfiguration Config { get; }
			public Configuration(IConfiguration Config)
			{
				this.Config = Config;
			}
			public string GetValue(string Path)
			{
				return Config[Path];
			}
		}

		public static IServiceCollection AddConfiguration(this IServiceCollection sc)
		{
			return sc.AddSingleton<Settings.IConfiguration, Configuration>();
		}
		public static IServiceCollection AddMSConfiguration(this IServiceCollection sc)
		{
			sc.AddSingleton(sp => {
				//var pr = sp.Resolve<IFilePathResolver>();

				var configuration =(IConfiguration) new ConfigurationBuilder()
					.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
					.AddJsonFile("appsettings.json")
					.Build();
				return configuration;
			});
			return sc;
		}
	}
}
