/// <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="options">A method that can set additional DotVVM options, like temporary file stores, or replace default DotVVM components with custom ones.</param>
        public static IServiceCollection AddDotVVM(this IServiceCollection services, Action <IDotvvmOptions> options = null)
        {
            services
            .AddAuthorization()
            .AddDataProtection();

            DotvvmServiceCollectionExtensions.RegisterDotVVMServices(services);

            services.TryAddSingleton <ICsrfProtector, DefaultCsrfProtector>();
            services.TryAddSingleton <IViewModelProtector, DefaultViewModelProtector>();
            services.TryAddSingleton <IEnvironmentNameProvider, DotvvmEnvironmentNameProvider>();

            if (options != null)
            {
                var builder = new DotvvmOptions(services);
                options(builder);
            }

            return(services);
        }
Пример #2
0
        /// <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="options">A method that can set additional DotVVM options, like temporary file stores, or replace default DotVVM components with custom ones.</param>
        public static IServiceCollection AddDotVVM(this IServiceCollection services, Action <IDotvvmOptions> options = null)
        {
            services
            .AddAuthorization()
            .AddDataProtection();

            DotvvmServiceCollectionExtensions.RegisterDotVVMServices(services);

            services.TryAddSingleton <ICsrfProtector, DefaultCsrfProtector>();
            services.TryAddSingleton <ICookieManager, ChunkingCookieManager>();
            services.TryAddSingleton <IViewModelProtector, DefaultViewModelProtector>();
            services.TryAddSingleton <IEnvironmentNameProvider, DotvvmEnvironmentNameProvider>();
            services.TryAddScoped <DotvvmRequestContextStorage>(_ => new DotvvmRequestContextStorage());
            services.TryAddScoped <IDotvvmRequestContext>(s => s.GetRequiredService <DotvvmRequestContextStorage>().Context);

            if (options != null)
            {
                var builder = new DotvvmOptions(services);
                options(builder);
            }

            return(services);
        }