static int Main(string[] args) { s_log.Info("Starting..."); try { //get builders and register services var backgroundServiceBuilder = BackgroundServiceEngine.Instance.BackgroundServiceBuilder; ConfigureContainer(backgroundServiceBuilder); BackgroundServiceEngine.Instance.Build(); IContainer container = BackgroundServiceEngine.Instance.BackgroundServiceContainerManager.Container; ScheduleJobServiceConfiguratorExtensions.SchedulerFactory = () => container.Resolve <IScheduler>(); HostFactory.Run(conf => { conf.SetServiceName(ConfigurationManager.AppSettings["ServiceName"]); conf.SetDisplayName(ConfigurationManager.AppSettings["ServiceName"]); conf.UseLog4Net(); conf.UseAutofacContainer(container); conf.Service <ServiceCore>(svc => { svc.ConstructUsingAutofacContainer(); svc.WhenStarted(o => o.Start()); svc.WhenStopped(o => { o.Stop(); container.Dispose(); }); ConfigureScheduler(svc); }); }); s_log.Info("Shutting down..."); log4net.LogManager.Shutdown(); //start StartupTask manually var auditLogStartupTask = new AuditLogStartupTask(); auditLogStartupTask.Execute(); return(0); } catch (Exception ex) { s_log.Fatal("Unhandled exception", ex); log4net.LogManager.Shutdown(); return(1); } }
// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder appBuilder) { // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); appBuilder.UseAutofacMiddleware(AutoFacConfig.Initialize(config)); //appBuilder.UseAutofacWebApi(config); appBuilder.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); appBuilder.UseWebApi(config); //start StartupTask manually var auditLogStartupTask = new AuditLogStartupTask(); auditLogStartupTask.Execute(); }