public static void CreateScheduler(IUnityContainer container = null) { if (container == null) { container = Bootstrapper.Initialize(); } var schedulerHostStartUpOptionText = ConfigurationManager.AppSettings["SchedulerHost"]; if (string.IsNullOrEmpty(schedulerHostStartUpOptionText)) { Trace.TraceError("SchedulerHost parameter not found in Web.Config. Scheduler not started"); } else { StartUpOption startUpOption; try { startUpOption = (StartUpOption) Enum.Parse(typeof(StartUpOption), schedulerHostStartUpOptionText); } catch (Exception ex) { Trace.TraceError( "Can't parse SchedulerHost parameter from web.config. Scheduler host not started. Expected values: Primary, Secondary, None." + Environment.NewLine + ex); startUpOption = StartUpOption.None; } if (startUpOption != StartUpOption.None) { var schedulerHost = new SchedulerHost(startUpOption == StartUpOption.Primary, t => container.Resolve(t, null), () => (IAppConfigRepository)container.Resolve(typeof(IAppConfigRepository), null) ); HostingEnvironment.RegisterObject(schedulerHost); schedulerHost.Start(); } } }
/// <summary> /// Integrates Unity when the application starts. /// </summary> public static void Start() { var container = UnityConfig.GetConfiguredContainer(); //Add Unity extension for mvc sitemap dependency injection container.AddNewExtension <MvcSiteMapProviderContainerExtension>(); FilterProviders.Providers.Remove(FilterProviders.Providers.OfType <FilterAttributeFilterProvider>().First()); FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container)); var dependencyResolver = new UnityDependencyResolver(container); var locatorProvider = new UnityDependencyResolverServiceLocatorProvider(dependencyResolver); ServiceLocator.SetLocatorProvider(() => locatorProvider); DependencyResolver.SetResolver(dependencyResolver); GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container); if (!AzureCommonHelper.IsAzureEnvironment() && AppConfigConfiguration.Instance.Setup.IsCompleted) { SchedulerHost.CreateScheduler(); } }
public static void CreateScheduler(IUnityContainer container = null) { if (container == null) { container = Bootstrapper.Initialize(); } var schedulerHostStartUpOptionText = ConfigurationManager.AppSettings["SchedulerHost"]; if (string.IsNullOrEmpty(schedulerHostStartUpOptionText)) { Trace.TraceError("SchedulerHost parameter not found in Web.Config. Scheduler not started"); } else { StartUpOption startUpOption; try { startUpOption = (StartUpOption) Enum.Parse(typeof(StartUpOption), schedulerHostStartUpOptionText); } catch (Exception ex) { Trace.TraceError( "Can't parse SchedulerHost parameter from web.config. Scheduler host not started. Expected values: Primary, Secondary, None." + Environment.NewLine + ex); startUpOption = StartUpOption.None; } if (startUpOption != StartUpOption.None) { var schedulerHost = new SchedulerHost(startUpOption == StartUpOption.Primary, t => container.Resolve(t, null), () => (IAppConfigRepository)container.Resolve(typeof(IAppConfigRepository), null) ); HostingEnvironment.RegisterObject(schedulerHost); schedulerHost.Start(); } } }