using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using NLog; using System.Net; using System.Runtime.CompilerServices; using YieldChain.Commons; using YLErp.Modules.DataCacheModule; namespace YLErp { public class Program { static IServiceProvider ServiceProvider; [ModuleInitializer] internal static void M1() { if (string.Equals(Environment.GetEnvironmentVariable("YLErp_UNIT_TEST_SKIP_INITIALIZATION"), "1", StringComparison.Ordinal)) return; Console.WriteLine("version--" + AppManager.Version); var logger = NLog.LogManager.Setup().GetCurrentClassLogger(); logger.Debug("init main"); IConfiguration configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); var services = new ServiceCollection(); YLServiceLocator.SetServiceCollection(services); AppManager.Initialize(YLErp.Enums.SubSystemName.UnitTest, configuration); DataCacheManager.UpdateOnce(); services.AddHttpClient("") .ConfigurePrimaryHttpMessageHandler(messageHandler => { var handler = new HttpClientHandler(); if (handler.SupportsAutomaticDecompression) { handler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; } return handler; }); ServiceProvider = services.BuildServiceProvider(); YLServiceLocator.SetServiceProvider(ServiceProvider); OtcAppContext.Initialize(s => { var s2 = s.Trim('/').Replace("/", "\\"); return @"d:\\" + s2; }); } public static T GetService() { return ServiceProvider.GetService(); } } }