private static void AddMvc(SchubertServicesBuilder services, SchubertWebBuilder featureBuilder, SchubertWebOptions options) { Action <MvcOptions> configure = mvc => { if (!options.GlobalRoutePrefix.IsNullOrWhiteSpace()) { mvc.Conventions.Insert(0, new RoutePrefixConvention(new RouteAttribute(options.GlobalRoutePrefix.Trim()))); } }; switch (options.MvcFeatures) { case MvcFeatures.Full: var mvcBuilder = services.ServiceCollection.AddMvc(configure); featureBuilder.MvcSetup?.Invoke(mvcBuilder); mvcBuilder.AddJsonOptions(json => json.SerializerSettings.ContractResolver = GetContractResolver(options.JsonCaseStyle, options.JsonResolver)) .AddRazorOptions(rveo => { rveo.FileProviders.Insert(0, new ModuleFileProvider(rveo.FileProviders.FirstOrDefault())); rveo.ViewLocationExpanders.Insert(0, new ModuleViewLocationExpander()); }); //services.ServiceCollection.AddAntiforgery(); break; case MvcFeatures.Core: var coreBuilder = services.ServiceCollection.AddMvcCore(configure); featureBuilder.MvcCoreSetup?.Invoke(coreBuilder); break; case MvcFeatures.Api: var apiBuilder = services.ServiceCollection.AddMvcCore(configure); featureBuilder.MvcCoreSetup?.Invoke(apiBuilder); apiBuilder.AddApiExplorer() .AddAuthorization() .AddFormatterMappings() .AddJsonFormatters(settings => settings.ContractResolver = GetContractResolver(options.JsonCaseStyle, options.JsonResolver)) .AddDataAnnotations() .AddCors(); featureBuilder.AddWebApiConventions(); break; default: return; } }