/// <summary> /// Adds DotVVM services with authorization and data protection to the specified <see cref="IServiceCollection" />. /// </summary> /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param> /// <param name="configurator">The <see cref="IDotvvmServiceConfigurator"/> instance.</param> public static IServiceCollection AddDotVVM(this IServiceCollection services, IDotvvmServiceConfigurator configurator) { AddDotVVMServices(services); var dotvvmServices = new DotvvmServiceCollection(services); startupTracer.TraceEvent(StartupTracingConstants.DotvvmConfigurationUserServicesRegistrationStarted); configurator.ConfigureServices(dotvvmServices); startupTracer.TraceEvent(StartupTracingConstants.DotvvmConfigurationUserServicesRegistrationFinished); return(services); }
private static DotvvmConfiguration UseDotVVM(this IAppBuilder app, string applicationRootPath, bool useErrorPages, bool debug, IDotvvmServiceConfigurator configurator, IDotvvmStartup startup, Func <IServiceCollection, IServiceProvider> serviceProviderFactoryMethod = null, Action <DotvvmConfiguration> modifyConfiguration = null) { var startupTracer = new DiagnosticsStartupTracer(); startupTracer.TraceEvent(StartupTracingConstants.AddDotvvmStarted); var config = DotvvmConfiguration.CreateDefault(s => { s.TryAddSingleton <IDataProtectionProvider>(p => new DefaultDataProtectionProvider(app)); s.TryAddSingleton <IDotvvmCacheAdapter, DefaultDotvvmCacheAdapter>(); s.TryAddSingleton <IViewModelProtector, DefaultViewModelProtector>(); s.TryAddSingleton <ICsrfProtector, DefaultCsrfProtector>(); s.TryAddSingleton <IEnvironmentNameProvider, DotvvmEnvironmentNameProvider>(); s.TryAddSingleton <ICookieManager, ChunkingCookieManager>(); s.TryAddSingleton <IRequestCancellationTokenProvider, RequestCancellationTokenProvider>(); s.TryAddScoped <DotvvmRequestContextStorage>(_ => new DotvvmRequestContextStorage()); s.TryAddScoped <IDotvvmRequestContext>(services => services.GetRequiredService <DotvvmRequestContextStorage>().Context); s.AddSingleton <IDotvvmViewCompilationService, DotvvmViewCompilationService>(); s.TryAddSingleton <IStartupTracer>(startupTracer); startupTracer.TraceEvent(StartupTracingConstants.DotvvmConfigurationUserServicesRegistrationStarted); configurator?.ConfigureServices(new DotvvmServiceCollection(s)); startupTracer.TraceEvent(StartupTracingConstants.DotvvmConfigurationUserServicesRegistrationFinished); }, serviceProviderFactoryMethod); config.Debug = debug; config.ApplicationPhysicalPath = applicationRootPath; startupTracer.TraceEvent(StartupTracingConstants.DotvvmConfigurationUserConfigureStarted); startup.Configure(config, applicationRootPath); startupTracer.TraceEvent(StartupTracingConstants.DotvvmConfigurationUserConfigureFinished); if (useErrorPages) { app.Use <DotvvmErrorPageMiddleware>(); } modifyConfiguration?.Invoke(config); config.Freeze(); startupTracer.TraceEvent(StartupTracingConstants.UseDotvvmStarted); app.Use <DotvvmMiddleware>(config, new List <IMiddleware> { ActivatorUtilities.CreateInstance <DotvvmCsrfTokenMiddleware>(config.ServiceProvider), ActivatorUtilities.CreateInstance <DotvvmLocalResourceMiddleware>(config.ServiceProvider), DotvvmFileUploadMiddleware.TryCreate(config.ServiceProvider), new DotvvmReturnedFileMiddleware(), new DotvvmRoutingMiddleware() }.Where(t => t != null).ToArray()); startupTracer.TraceEvent(StartupTracingConstants.UseDotvvmFinished); var compilationConfiguration = config.Markup.ViewCompilation; compilationConfiguration.HandleViewCompilation(config, startupTracer); if (config.ServiceProvider.GetService <IDiagnosticsInformationSender>() is IDiagnosticsInformationSender sender) { startupTracer.NotifyStartupCompleted(sender); } return(config); }
private static DotvvmConfiguration UseDotVVM(this IAppBuilder app, string applicationRootPath, bool useErrorPages, bool debug, IDotvvmServiceConfigurator configurator, IDotvvmStartup startup, Func <IServiceCollection, IServiceProvider> serviceProviderFactoryMethod = null) { var config = DotvvmConfiguration.CreateDefault(s => { s.TryAddSingleton <IDataProtectionProvider>(p => new DefaultDataProtectionProvider(app)); s.TryAddSingleton <IViewModelProtector, DefaultViewModelProtector>(); s.TryAddSingleton <ICsrfProtector, DefaultCsrfProtector>(); s.TryAddSingleton <IEnvironmentNameProvider, DotvvmEnvironmentNameProvider>(); s.TryAddSingleton <ICookieManager, ChunkingCookieManager>(); s.TryAddScoped <DotvvmRequestContextStorage>(_ => new DotvvmRequestContextStorage()); s.TryAddScoped <IDotvvmRequestContext>(services => services.GetRequiredService <DotvvmRequestContextStorage>().Context); configurator?.ConfigureServices(new DotvvmServiceCollection(s)); }, serviceProviderFactoryMethod); config.Debug = debug; config.ApplicationPhysicalPath = applicationRootPath; startup.Configure(config, applicationRootPath); if (useErrorPages) { app.Use <DotvvmErrorPageMiddleware>(); } app.Use <DotvvmMiddleware>(config, new List <IMiddleware> { ActivatorUtilities.CreateInstance <DotvvmLocalResourceMiddleware>(config.ServiceProvider), DotvvmFileUploadMiddleware.TryCreate(config.ServiceProvider), new DotvvmReturnedFileMiddleware(), new DotvvmRoutingMiddleware() }.Where(t => t != null).ToArray()); config.Freeze(); return(config); }
/// <summary> /// Adds DotVVM to the <see cref="IAppBuilder" /> request execution pipeline. /// </summary> /// <param name="app">The <see cref="IAppBuilder" /> instance.</param> /// <param name="startup">The <see cref="IDotvvmStartup" /> instance.</param> /// <param name="serviceConfigurator">The <see cref="IDotvvmServiceConfigurator" /> instance.</param> /// <param name="applicationRootPath">The path to application's root directory. It is used to resolve paths to views, etc.</param> /// <param name="useErrorPages"> /// A value indicating whether to show detailed error page if an exception occurs. Disable this /// in production. /// </param> /// <param name="debug">A value indicating whether the application should run in debug mode.</param> /// <param name="serviceProviderFactoryMethod">Register factory method to create your own instance of IServiceProvider.</param> /// <param name="modifyConfiguration">An action that allows modifying configuration before it's frozen.</param> public static DotvvmConfiguration UseDotVVM(this IAppBuilder app, IDotvvmStartup startup, IDotvvmServiceConfigurator serviceConfigurator, string applicationRootPath, bool useErrorPages = true, bool debug = true, Func <IServiceCollection, IServiceProvider> serviceProviderFactoryMethod = null, Action <DotvvmConfiguration> modifyConfiguration = null) { return(app.UseDotVVM(applicationRootPath, useErrorPages, debug, serviceConfigurator, startup, serviceProviderFactoryMethod, modifyConfiguration)); }