/// <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....."); } } }
protected virtual void Application_Start(object sender, EventArgs e) { Config.Current.IgnoreAssemblies(IgnoreAssemblyFiles).With(); IIocBuilder builder = CreateIocBuilder(); IocInstance.RegisterBuilder(builder); IocInstance.AutoRegister(Config.Current.TypesToScan); BuildeIOC(builder); IocInstance.Build(); IocInstance.Start(this.Context); var appEventHandlers = IocInstance.Container.ResolveOptional <IEnumerable <IWebAppEventHandler> >(); if (appEventHandlers != null) { foreach (var aeh in appEventHandlers.OrderBy(o => o.ExecuteOrder)) { aeh.Application_Start(sender, e); } } }