#pragma warning restore IDE0044 // Add readonly modifier /// <summary> /// Initializes a new instance of the <see cref="UmbracoRequestMiddleware"/> class. /// </summary> public UmbracoRequestMiddleware( ILogger <UmbracoRequestMiddleware> logger, IUmbracoContextFactory umbracoContextFactory, IRequestCache requestCache, PublishedSnapshotServiceEventHandler publishedSnapshotServiceEventHandler, IEventAggregator eventAggregator, IProfiler profiler, IHostingEnvironment hostingEnvironment, UmbracoRequestPaths umbracoRequestPaths, BackOfficeWebAssets backOfficeWebAssets, IOptions <SmidgeOptions> smidgeOptions, IRuntimeState runtimeState, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor) { _logger = logger; _umbracoContextFactory = umbracoContextFactory; _requestCache = requestCache; _publishedSnapshotServiceEventHandler = publishedSnapshotServiceEventHandler; _eventAggregator = eventAggregator; _hostingEnvironment = hostingEnvironment; _umbracoRequestPaths = umbracoRequestPaths; _backOfficeWebAssets = backOfficeWebAssets; _runtimeState = runtimeState; _variationContextAccessor = variationContextAccessor; _defaultCultureAccessor = defaultCultureAccessor; _smidgeOptions = smidgeOptions.Value; _profiler = profiler as WebProfiler; // Ignore if not a WebProfiler }
public void StartServices() { // DI ready ServiceLocator.Start = (IServiceLocator locator) => { IProfiler profiler = new WebProfiler(); IApplicationHost host = new WebApplicationHost(profiler); ILocalizer localizer = new WebLocalizer(host); IDbContext dbContext = new SqlDbContext( profiler as IDataProfiler, host as IDataConfiguration, localizer as IDataLocalizer, host as ITenantManager); ILogger logger = new WebLogger(host, dbContext); IMessageService emailService = new IdentityEmailService(logger, host); IMessaging messaging = new MessageProcessor(host, dbContext, emailService, logger); IRenderer renderer = new XamlRenderer(profiler, host); IWorkflowEngine workflowEngine = new WorkflowEngine(host, dbContext, messaging); IDataScripter scripter = new VueDataScripter(host, localizer); ISmsService smsService = new SmsService(dbContext, logger); IExternalLoginManager externalLoginManager = new ExternalLoginManager(dbContext); IUserStateManager userStateManager = new WebUserStateManager(host, dbContext); IExternalDataProvider dataProvider = new ExternalDataContext(); IScriptProcessor scriptProcessor = new ScriptProcessor(scripter, host); locator.RegisterService <IDbContext>(dbContext); locator.RegisterService <IProfiler>(profiler); locator.RegisterService <IApplicationHost>(host); locator.RegisterService <IRenderer>(renderer); locator.RegisterService <IWorkflowEngine>(workflowEngine); locator.RegisterService <IMessaging>(messaging); locator.RegisterService <ILocalizer>(localizer); locator.RegisterService <IDataScripter>(scripter); locator.RegisterService <ILogger>(logger); locator.RegisterService <IMessageService>(emailService); locator.RegisterService <ISmsService>(smsService); locator.RegisterService <IExternalLoginManager>(externalLoginManager); locator.RegisterService <IUserStateManager>(userStateManager); locator.RegisterService <IExternalDataProvider>(dataProvider); locator.RegisterService <IScriptProcessor>(scriptProcessor); HttpContext.Current.Items.Add("ServiceLocator", locator); }; ServiceLocator.GetCurrentLocator = () => { if (HttpContext.Current == null) { throw new InvalidProgramException("There is no http context"); } var currentContext = HttpContext.Current; var locator = currentContext.Items["ServiceLocator"]; if (locator == null) { new ServiceLocator(); } return(HttpContext.Current.Items["ServiceLocator"] as IServiceLocator); }; }
/// <summary> /// Ensure the current profiler is the web profiler /// </summary> protected override void InitializeProfilerResolver() { base.InitializeProfilerResolver(); //Set the profiler to be the web profiler var profiler = new WebProfiler(); ProfilerResolver.Current.SetProfiler(profiler); profiler.Start(); }
public void StartServices() { // DI ready IServiceLocator locator = ServiceLocator.Current; IProfiler profiler = new WebProfiler(); IApplicationHost host = new WebApplicationHost(profiler); IDbContext dbContext = new SqlDbContext(host); //IRenderer renderer = new XamlRenderer(); //IWorkflowEngine workflowEngine = new WorkflowEngine(host, dbContext); locator.RegisterService <IDbContext>(dbContext); locator.RegisterService <IProfiler>(profiler); locator.RegisterService <IApplicationHost>(host); //locator.RegisterService<IRenderer>(renderer); //locator.RegisterService<IWorkflowEngine>(workflowEngine); }
private static IProfiler GetWebProfiler(IConfiguration config) { var isDebug = config.GetValue <bool>($"{Cms.Core.Constants.Configuration.ConfigHosting}:Debug"); // create and start asap to profile boot if (!isDebug) { // should let it be null, that's how MiniProfiler is meant to work, // but our own IProfiler expects an instance so let's get one return(new NoopProfiler()); } var webProfiler = new WebProfiler(); webProfiler.StartBoot(); return(webProfiler); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ServiceLocator.Start = (locator) => { IProfiler profiler = new WebProfiler(); IApplicationHost host = new WebApplicationHost(profiler); ILocalizer localizer = new WebLocalizer(host); IDbContext dbContext = new SqlDbContext( profiler as IDataProfiler, host as IDataConfiguration, localizer as IDataLocalizer, host as ITenantManager); IDataScripter scripter = new VueDataScripter(host, localizer); ILogger logger = new WebLogger(host, dbContext); locator.RegisterService <IDbContext>(dbContext); locator.RegisterService <IProfiler>(profiler); locator.RegisterService <IApplicationHost>(host); locator.RegisterService <ILocalizer>(localizer); locator.RegisterService <IDataScripter>(scripter); locator.RegisterService <ILogger>(logger); HttpContext.Current.Items.Add("ServiceLocator", locator); }; ServiceLocator.GetCurrentLocator = () => { var locator = HttpContext.Current.Items["ServiceLocator"]; if (locator == null) { new ServiceLocator(); } return(HttpContext.Current.Items["ServiceLocator"] as IServiceLocator); }; }
public static void StartServices(IAppBuilder app) { // DI ready ServiceLocator.Start = (IServiceLocator locator) => { IProfiler profiler = new WebProfiler(); IUserLocale userLocale = new WebUserLocale(); IApplicationHost host = new WebApplicationHost(profiler, userLocale, locator); ILocalizer localizer = new WebLocalizer(host, userLocale); ITokenProvider tokenProvider = new WebTokenProvider(); IDbContext dbContext = new SqlDbContext( profiler as IDataProfiler, host as IDataConfiguration, localizer as IDataLocalizer, host as ITenantManager, tokenProvider); ILogger logger = new WebLogger(host, dbContext); IMessageService emailService = new IdentityEmailService(logger, host); ISmsService smsService = new SmsService(dbContext, logger); IRenderer renderer = new XamlRenderer(profiler, host); IDataScripter scripter = new VueDataScripter(host, localizer); IExternalLoginManager externalLoginManager = new ExternalLoginManager(dbContext); IUserStateManager userStateManager = new WebUserStateManager(host, dbContext); IMessaging messaging = new MessageProcessor(host, dbContext, emailService, smsService, logger); IWorkflowEngine workflowEngine = new WorkflowEngine(host, dbContext, messaging); IExternalDataProvider dataProvider = new ExternalDataContext(); IScriptProcessor scriptProcessor = new ScriptProcessor(scripter, host); IHttpService httpService = new HttpService(); IJavaScriptEngine javaScriptEngine = new JavaScriptEngine(dbContext, host, smsService); locator.RegisterService <IDbContext>(dbContext); locator.RegisterService <IProfiler>(profiler); locator.RegisterService <IApplicationHost>(host); locator.RegisterService <IRenderer>(renderer); locator.RegisterService <IWorkflowEngine>(workflowEngine); locator.RegisterService <IMessaging>(messaging); locator.RegisterService <IUserLocale>(userLocale); locator.RegisterService <ILocalizer>(localizer); locator.RegisterService <IDataScripter>(scripter); locator.RegisterService <ILogger>(logger); locator.RegisterService <IMessageService>(emailService); locator.RegisterService <ISmsService>(smsService); locator.RegisterService <IExternalLoginManager>(externalLoginManager); locator.RegisterService <IUserStateManager>(userStateManager); locator.RegisterService <IExternalDataProvider>(dataProvider); locator.RegisterService <IScriptProcessor>(scriptProcessor); locator.RegisterService <IHttpService>(httpService); locator.RegisterService <IJavaScriptEngine>(javaScriptEngine); locator.RegisterService <ITokenProvider>(tokenProvider); IDataProtectionProvider dataProtection = app.GetDataProtectionProvider(); locator.RegisterService <IDataProtectionProvider>(dataProtection); if (HttpContext.Current != null) { HttpContext.Current.Items.Add("ServiceLocator", locator); } }; IServiceLocator GetOrCreateStatic() { if (_currentLocator == null) { _currentLocator = new ServiceLocator(); } return(_currentLocator); } ServiceLocator.GetCurrentLocator = () => { if (HttpContext.Current == null) { return(GetOrCreateStatic()); } var currentContext = HttpContext.Current; var locator = currentContext.Items["ServiceLocator"]; if (locator == null) { var loc = new ServiceLocator(); // side effects var fromHttp = HttpContext.Current.Items["ServiceLocator"] as IServiceLocator; if (loc != fromHttp) { throw new InvalidOperationException("Invalid service locator"); } } return(HttpContext.Current.Items["ServiceLocator"] as IServiceLocator); }; }