public static void AddBrickPile(this IServiceCollection services)
        {
            _serviceProvider = services.BuildServiceProvider();

            services.AddMvc().ConfigureApplicationPartManager(manager =>
            {
                var feature = new ControllerFeature();
                manager.PopulateFeature(feature);
                services.AddSingleton<IControllerMapper>(new ControllerMapper(feature));
            });

            services.AddRouting(options =>
            {
                options.AppendTrailingSlash = true;
                options.LowercaseUrls = true;
            });

            services.Configure<MvcOptions>(options =>
            {
                options.ModelBinderProviders.Insert(0, new DefaultModelBinderProvider(DocumentStore));
                options.Filters.Add(typeof(PublishedFilterAttribute), 1);
                options.Filters.Add(typeof(AuthorizeFilterAttribute), 2);
            });

            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton(DocumentStore);
            services.AddTransient<IRouteResolverTrie>(provider => new RouteResolverTrie(provider.GetService<IDocumentStore>()));
            services.AddTransient<IBricsContextAccessor>(provider => new BricsContextAccessor(provider.GetService<IHttpContextAccessor>(), provider.GetService<IDocumentStore>()));
        }
        public static void AddDefaultServices(this IServiceCollection services)
        {
            services.AddMvc();

            services.AddScoped<LogExceptionFilter>();
            services.AddScoped<ExceptionResponseFilter>();
            services.AddScoped<NullFilter>();
        }
        public static void AddDynamicData(this IServiceCollection services)
        {
            services.AddMvc();

            services.AddSingleton<IDataModelDescriptorProvider, DataModelDescriptorProvider>();

            services.Configure<RazorViewEngineOptions>(options =>
                options.FileProvider = new ListOfFileProvider(
                    options.FileProvider,
                    new EmbeddedFileProvider(typeof (Guard).GetTypeInfo().Assembly, nameof(ModernDynamicData.Views))
                    )
                );
        }
Пример #4
0
 public static IServiceCollection AddPanther(this IServiceCollection services)
 {
     services.AddIdentity<User, Role>()
         .AddDefaultTokenProviders();
     services.AddMvc();
     services.ConfigureMvc(options =>
     {
         options.Filters.Add(new SecurityFilterAttribute());
     });
     services.ConfigureRazorViewEngine(razor =>
     {
         razor.ViewLocationExpanders.Add(new ViewLocationExpanderDescriptor(typeof(PantherViewLocationExpander)));
     });
     PantherServices.GetDefaultServices(services);
     return services;
 }
Пример #5
0
        /// <summary>
        /// Adds MVC services to the specified <see cref="IServiceCollection" />.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
        /// <param name="setupAction">An <see cref="Action{MvcOptions}"/> to configure the provided <see cref="MvcOptions"/>.</param>
        /// <returns>An <see cref="IMvcBuilder"/> that can be used to further configure the MVC services.</returns>
        public static IMvcBuilder AddMvc(this IServiceCollection services, Action<MvcOptions> setupAction)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (setupAction == null)
            {
                throw new ArgumentNullException(nameof(setupAction));
            }

            var builder = services.AddMvc();
            builder.Services.Configure(setupAction);

            return builder;
        }
Пример #6
0
        public static void AddLightcore(this IServiceCollection services, IConfiguration config)
        {
            // Add standard MVC services and Lightcore ValueProvider
            services.AddMvc(options => { options.ValueProviderFactories.Add(new LightcoreValueProviderFactory()); });

            // Add standard caching
            services.AddCaching();

            // Add Lightcore configuration so it can be used as a dependency IOptions<LightcoreConfig> config
            services.Configure<LightcoreOptions>(config.GetSection("LightcoreOptions"));

            // Add Lightcore services
            services.AddSingleton<IItemProvider, LightcoreApiItemProvider>();
            services.AddSingleton<IItemUrlService, ItemUrlService>();

            // Add Lightcore pipelines
            services.AddSingleton<StartupPipeline>();
            services.AddSingleton<RequestPipeline>();
            services.AddSingleton<RenderFieldPipeline>();
            services.AddSingleton<RenderRenderingPipeline>();
            services.AddSingleton<RenderPlaceholderPipeline>();
        }
Пример #7
0
        public static IServiceCollection AddUmbraco(this IServiceCollection services)
        {
            services.AddUmbracoCore();
            services.AddCaching();
            services.AddSession();
            services.AddMvc();
            //services.AddAuthentication();
            //services.AddAuthorization();

            //replace the MVC one
            services.AddSingleton<IAssemblyProvider, MvcPluginAssemblyProvider>();

            services.AddSingleton<IUmbracoAssemblyProvider, PluginAssemblyProvider>(provider =>
            {
                var hosting = provider.GetRequiredService<IApplicationEnvironment>();
                var fileProvider = new PhysicalFileProvider(hosting.ApplicationBasePath);
                return new PluginAssemblyProvider(fileProvider, provider.GetRequiredService<ILoggerFactory>(),
                    PlatformServices.Default.AssemblyLoadContextAccessor,
                    PlatformServices.Default.AssemblyLoaderContainer);
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy(
                    "umbraco-backoffice",
                    builder => builder
                        .AddAuthenticationSchemes("umbraco-backoffice")
                        .RequireAuthenticatedUser()
                        .RequireClaim("umbraco-backoffice")
                    );
            });

            services.Configure<MvcOptions>(options =>
            {
                options.ModelBinders.Insert(0, new PublishedContentModelBinder());
            });

            //services.AddIdentity<BackOfficeUser, IdentityRole>();

            services.AddSingleton<IControllerActivator, UmbracoControllerActivator>();
            services.AddTransient<UmbracoControllerHelper>();
            //services.AddSingleton<UmbracoAssemblyProvider>();
            services.AddSingleton<IUmbracoConfig, UmbracoConfig>();
            services.AddSingleton<UmbracoControllerTypeCollection>();
            services.AddSingleton<SurfaceFormHelper>();
            services.AddSingleton<IControllerPropertyActivator, ProxiedViewDataDictionaryPropertyActivator>();

            services.AddScoped<UmbracoContext>();
            services.AddScoped<RoutingContext>();
            services.AddScoped<PublishedContentRequest>();

            //TODO: default is no last chance finder (for now)
            services.AddScoped<ILastChanceContentFinder>(provider => (ILastChanceContentFinder) null);
            services.AddScoped<UrlProvider>(provider => new UrlProvider(
                provider.GetRequiredService<UmbracoContext>(),
                provider.GetServices<IUrlProvider>(),
                UrlProviderMode.Auto));

            return services;
        }
        public static void ConfigureIdentityServerServices(this IServiceCollection services, string connectionString)
        {
            services
                .AddEntityFrameworkSqlServer()
                .AddDbContext<UserContext>(o => o.UseSqlServer(connectionString))
                .AddDbContext<IdentityServerOperationalContext>(o => o.UseSqlServer(connectionString))
                .AddIdentity<User, IdentityRole>()
                .AddEntityFrameworkStores<UserContext>()
                .AddDefaultTokenProviders();

            var identity = services
                .AddIdentityServer(o => o.RequireSsl = false)
                .AddInMemoryClients(Clients)
                .AddInMemoryScopes(Scopes);

            identity.SetSigningCredential(IdentityServerSigning.SecurityKey);

            identity.ConfigureEntityFramework().RegisterOperationalStores<IdentityServerOperationalContext>();

            services.AddMvc();

            identity.Services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
            identity.Services.AddTransient<IProfileService, ProfileService>();
        }