/// <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 action delegate to configure the provided <see cref="MvcOptions"/>.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IMvcBuilder AddMvc(this IServiceCollection services, Action<MvcOptions> setupAction) { if (services == null) { throw new ArgumentNullException(nameof(services)); } var builder = services.AddMvcCore(); builder.AddApiExplorer(); builder.AddAuthorization(); // Order added affects options setup order // Default framework order builder.AddFormatterMappings(); builder.AddViews(); builder.AddRazorViewEngine(); // +1 order builder.AddDataAnnotations(); // +1 order // +10 order builder.AddJsonFormatters(); builder.AddCors(); if (setupAction != null) { builder.Services.Configure(setupAction); } return new MvcBuilder(services); }
/// <summary> /// Adds MVC services to the specified <see cref="IServiceCollection" />. /// </summary> /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param> /// <returns>An <see cref="IMvcBuilder"/> that can be used to further configure the MVC services.</returns> public static IMvcBuilder AddMvc(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } var builder = services.AddMvcCore(); builder.AddApiExplorer(); builder.AddAuthorization(); AddDefaultFrameworkParts(builder.PartManager); // Order added affects options setup order // Default framework order builder.AddFormatterMappings(); builder.AddViews(); builder.AddRazorViewEngine(); builder.AddCacheTagHelper(); // +1 order builder.AddDataAnnotations(); // +1 order // +10 order builder.AddJsonFormatters(); builder.AddCors(); return new MvcBuilder(builder.Services, builder.PartManager); }
public static IServiceCollection AddOrchardMvc(this IServiceCollection services) { services .AddMvcCore(options => { options.Filters.Add(new ModelBinderAccessorFilter()); options.Conventions.Add(new ModuleAreaRouteConstraintConvention()); options.ModelBinders.Insert(0, new CheckMarkModelBinder()); }) .AddViews() .AddViewLocalization() .AddRazorViewEngine() .AddJsonFormatters(); services.AddScoped<IModelUpdaterAccessor, LocalModelBinderAccessor>(); services.AddTransient<IFilterProvider, DependencyFilterProvider>(); services.AddTransient<IMvcRazorHost, TagHelperMvcRazorHost>(); services.AddScoped<IAssemblyProvider, OrchardMvcAssemblyProvider>(); services.AddSingleton<ICompilationService, DefaultRoslynCompilationService>(); services.Configure<RazorViewEngineOptions>(options => { var expander = new ModuleViewLocationExpander(); options.ViewLocationExpanders.Add(expander); }); return services; }
public static IServiceCollection AddOrchardMvc(this IServiceCollection services) { services .AddMvcCore(options => { options.Filters.Add(new ModelBinderAccessorFilter()); options.Filters.Add(typeof(AutoValidateAntiforgeryTokenAuthorizationFilter)); options.ModelBinderProviders.Insert(0, new CheckMarkModelBinderProvider()); }) .AddViews() .AddViewLocalization() .AddRazorViewEngine() .AddJsonFormatters(); services.AddScoped<IModelUpdaterAccessor, LocalModelBinderAccessor>(); services.AddTransient<IFilterProvider, DependencyFilterProvider>(); services.AddTransient<IApplicationModelProvider, ModuleAreaRouteConstraintApplicationModelProvider>(); services.Configure<RazorViewEngineOptions>(configureOptions: options => { var expander = new ModuleViewLocationExpander(); options.ViewLocationExpanders.Add(expander); var extensionLibraryService = services.BuildServiceProvider().GetService<IExtensionLibraryService>(); ((List<MetadataReference>)options.AdditionalCompilationReferences).AddRange(extensionLibraryService.MetadataReferences()); }); return services; }
public static void AddWebPages(this IServiceCollection services, WebPagesOptions webPagesOptions) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddMvcCore().AddRazorViewEngine(o => { o.ViewLocationFormats.Clear(); o.ViewLocationFormats.Add("/" + webPagesOptions.ViewsFolderName + "/{0}" + RazorViewEngine.ViewExtension); }); services.AddSingleton<WebPagesOptions>(webPagesOptions); services.AddSingleton<RazorViewToStringRenderer>(); services.AddSingleton<WebPagesRouter>(); }
public static IServiceCollection AddOrchardMvc(this IServiceCollection services) { services .AddMvcCore() .AddViews() .AddRazorViewEngine(); services.AddScoped<IAssemblyProvider, OrchardMvcAssemblyProvider>(); services.AddSingleton<ICompilationService, DefaultRoslynCompilationService>(); services.Configure<RazorViewEngineOptions>(options => { var expander = new ModuleViewLocationExpander(); options.ViewLocationExpanders.Add(expander); }); return services; }
public static IServiceCollection AddItasuMvc(this IServiceCollection services) { services .AddMvcCore(mvcOptions => { mvcOptions.Conventions.Add(new AreaControllerModelConvention()); mvcOptions.Conventions.Add(new ThemeControllerModelConvention()); }) .AddRazorViewEngine(options => { options.ViewLocationExpanders.Add(new RazorViewLocationExpander()); }) .AddViews() .AddAuthorization() .AddViewLocalization(); return services; }
public static IServiceCollection AddOrchardMvc(this IServiceCollection services) { services .AddMvcCore(options => { options.Filters.Add(new ModelBinderAccessorFilter()); options.Conventions.Add(new ModuleAreaRouteConstraintConvention()); options.ModelBinderProviders.Insert(0, new CheckMarkModelBinderProvider()); }) .AddViews() .AddViewLocalization() .AddRazorViewEngine() .AddJsonFormatters(); services.AddScoped<IModelUpdaterAccessor, LocalModelBinderAccessor>(); services.AddTransient<IFilterProvider, DependencyFilterProvider>(); services.AddTransient<IMvcRazorHost, TagHelperMvcRazorHost>(); //if (DnxPlatformServices.Default.LibraryManager != null) //{ // var partManager = GetApplicationPartManager(services); // var libraryManager = new OrchardLibraryManager(DnxPlatformServices.Default.LibraryManager); // var provider = new OrchardMvcAssemblyProvider( // libraryManager, // DnxPlatformServices.Default.AssemblyLoaderContainer, // new ExtensionAssemblyLoader( // PlatformServices.Default.Application, // DnxPlatformServices.Default.AssemblyLoadContextAccessor, // PlatformServices.Default.Runtime, // libraryManager)); // foreach (var assembly in provider.CandidateAssemblies) // { // partManager.ApplicationParts.Add(new AssemblyPart(assembly)); // } //} services.Configure<RazorViewEngineOptions>(configureOptions: options => { var expander = new ModuleViewLocationExpander(); options.ViewLocationExpanders.Add(expander); }); return services; }