// ReSharper disable once InconsistentNaming
        private static void AddDotVVMServices(IServiceCollection services)
        {
            var addAuthorizationMethod =
                Type.GetType("Microsoft.Extensions.DependencyInjection.AuthorizationServiceCollectionExtensions, Microsoft.AspNetCore.Authorization", throwOnError: false)
                ?.GetMethod("AddAuthorization", new[] { typeof(IServiceCollection) })
                ?? Type.GetType("Microsoft.Extensions.DependencyInjection.PolicyServiceCollectionExtensions, Microsoft.AspNetCore.Authorization.Policy", throwOnError: false)
                ?.GetMethod("AddAuthorization", new[] { typeof(IServiceCollection) })
                ?? throw new InvalidOperationException("Unable to find ASP.NET Core AddAuthorization method. You are probably using an incompatible version of ASP.NET Core.");

            addAuthorizationMethod.Invoke(null, new object[] { services });

            services.AddDataProtection();
            services.AddMemoryCache();
            DotvvmServiceCollectionExtensions.RegisterDotVVMServices(services);

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

            services.AddTransient <IDotvvmWarningSink, AspNetCoreLoggerWarningSink>();
        }
Exemple #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>
        public static IDotvvmBuilder AddDotVVM(this IServiceCollection services)
        {
            services
            .AddAuthorization()
            .AddDataProtection();

            DotvvmServiceCollectionExtensions.RegisterDotVVMServices(services);

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

            return(new DotvvmBuilder(services));
        }
        // ReSharper disable once InconsistentNaming
        private static void AddDotVVMServices(IServiceCollection services)
        {
            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);
        }
        /// <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);
        }
Exemple #5
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);
        }