/// <summary> /// 应用程序的主入口点。 /// </summary> static void Main(string[] args) { Config.Current.IgnoreAssemblies(IgnoreAssemblyFiles).With(); IIocBuilder builder = new AutofacBuilder(); IocInstance.RegisterBuilder(builder); IocInstance.AutoRegister(Config.Current.TypesToScan); builder.RegisterModule(new JsonNetModule()); builder.RegisterType <IChangeVersionManager, JsonChangeVersionManager>(LifeTimeScope.Singleton); builder.RegisterType <IObjectProvider <IEnumerable <VersionInfo> >, JsonFileObjectProvider <IEnumerable <VersionInfo> > >(LifeTimeScope.Singleton, getConstructorParameters: (ctx) => { Dictionary <string, object> paras = new Dictionary <string, object>(); paras.Add("jsonFile", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "versions.js")); paras.Add("jsonSerializer", ctx.Resolve <IJsonSerializer>()); return(paras); }); builder.RegisterConfig(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ioc.config")); IocInstance.Build(); IocInstance.Start(); if (args.Length > 0) { if (args.Any(o => o.ToLower() == "-monitor")) { if (args.Any(o => o.ToLower() == "-service")) { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new MonitorService() }; ServiceBase.Run(ServicesToRun); } else { Monitors.Start(); Console.WriteLine(":: Monitoring ::"); Console.ReadLine(); Monitors.Stop(); Console.WriteLine("Stopping....."); } } else if (args.Any(o => o.ToLower() == "-init")) { Console.WriteLine(":: Initializing ::"); IBatchIndexWriter biw = IocInstance.Container.Resolve <IBatchIndexWriter>(); biw.Run(); Console.WriteLine(":: Initialized ::"); Console.ReadLine(); Console.WriteLine("Stopping....."); } } }
/// <summary> /// 应用程序的主入口点。 /// </summary> static void Main(string[] args) { Config.Current.IgnoreAssemblies(IgnoreAssemblyFiles).With(); IIocBuilder builder = new AutofacBuilder(); IocInstance.RegisterBuilder(builder); IocInstance.AutoRegister(Config.Current.TypesToScan); builder.RegisterModule(new JsonNetModule()); builder.RegisterType<IChangeVersionManager, JsonChangeVersionManager>(LifeTimeScope.Singleton); builder.RegisterType<IObjectProvider<IEnumerable<VersionInfo>>, JsonFileObjectProvider<IEnumerable<VersionInfo>>>(LifeTimeScope.Singleton, getConstructorParameters: (ctx) => { Dictionary<string, object> paras = new Dictionary<string, object>(); paras.Add("jsonFile", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "versions.js")); paras.Add("jsonSerializer", ctx.Resolve<IJsonSerializer>()); return paras; }); builder.RegisterConfig(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ioc.config")); IocInstance.Build(); IocInstance.Start(); if (args.Length > 0) { if (args.Any(o => o.ToLower() == "-monitor")) { if (args.Any(o => o.ToLower() == "-service")) { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new MonitorService() }; ServiceBase.Run(ServicesToRun); } else { Monitors.Start(); Console.WriteLine(":: Monitoring ::"); Console.ReadLine(); Monitors.Stop(); Console.WriteLine("Stopping....."); } } else if (args.Any(o => o.ToLower() == "-init")) { Console.WriteLine(":: Initializing ::"); IBatchIndexWriter biw = IocInstance.Container.Resolve<IBatchIndexWriter>(); biw.Run(); Console.WriteLine(":: Initialized ::"); Console.ReadLine(); Console.WriteLine("Stopping....."); } } }
public IServiceProvider ConfigureServices(IServiceCollection services) { this.config = new BoardlessWebConfig(this.configurationRoot); services.AddWebApiService(this.config); services.AddMvc().AddControllersAsServices(); var builder = new AutofacBuilder(); builder.Populate(services); builder.RegisterModule(new BoardlessWebDIModule(this.executeAssembly, this.rootPath, this.configurationRoot, this.loggerFactory)); var scope = builder.Build(); var migrationService = scope.Resolve <IMigrationUseCase>(); migrationService.ExecuteAsync().GetAwaiter().GetResult(); return(builder.CreateServiceProvider()); }
/// <summary> /// 実行 /// </summary> public int Execute() { var builder = new AutofacBuilder(); builder.RegisterModule(new SubscriberDIModule(this.executeAssembly, this.rootPath, this.configurationRoot, this.loggerFactory)); using (var scope = builder.Build()) { var cts = scope.Resolve <CancellationTokenSource>(); var action = new Action <AssemblyLoadContext>(context => { cts.Cancel(false); }); AssemblyLoadContext.Default.Unloading += action; try { var app = scope.Resolve <SubscriberApplication>(); return(app.Execute(args)); } finally { AssemblyLoadContext.Default.Unloading -= action; } } }