protected override IMvcCoreBuilder ConfigureMvc(IMvcCoreBuilder builder) { return(builder.AddApiExplorer() .AddAuthorization() .AddCacheTagHelper() .AddCookieTempDataProvider() .AddDataAnnotations() .AddModelValidator() .AddRazorPages() .AddRazorViewEngine() .AddViews() .AddCors( options => options.AddDefaultPolicy( configure => { options.DefaultPolicyName = this.Options.ApiScope; configure.AllowAnyHeader() .AllowAnyMethod() .AllowAnyOrigin() .AllowCredentials(); })) .AddMvcOptions( options => { var policy = ScopePolicy.Create(this.Options.ApiScope); options.Filters.Add(new AuthorizeFilter(policy)); })); }
/// <summary> /// Configuring API help services using an <see cref="IMvcCoreBuilder"/>. /// </summary> /// <param name="builder">The <see cref="IMvcCoreBuilder" /> interface for configuring essential MVC services.</param> /// <param name="setupAction">An action to configure the <see cref="ApiHelpOptions"/>.</param> /// <returns>The <see cref="IMvcCoreBuilder" /> interface for configuring essential MVC services.</returns> public static IMvcCoreBuilder AddApiHelp(this IMvcCoreBuilder builder, Action <ApiHelpOptions> setupAction = null) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.AddApiExplorer(); AddApiHelpServices(builder.Services); if (setupAction != null) { builder.Services.Configure(setupAction); } else { builder.Services.Configure <ApiHelpOptions>(options => { options.IncludeSupportedMediaType = true; options.IgnoreObsoleteApi = true; options.GenerateStrategy = DocumentGenerateStrategy.Eager; }); } return(builder); }
public static IMvcCoreBuilder AddSwaggerSpecification(this IMvcCoreBuilder mvcBuilder) { mvcBuilder.Services .AddSwaggerGen(options => { options.SwaggerDoc("spec", new OpenApiInfo { Title = "Example Api", Version = "v1" }); }); return(mvcBuilder.AddApiExplorer()); }
/// <summary> /// 注册ApiExplorer生成服务 /// </summary> /// <param name="builder"></param> /// <param name="configureOptions"></param> /// <returns></returns> public static IMvcCoreBuilder AddApiExplorerGenerator(this IMvcCoreBuilder builder, Action <ApiExplorerGeneratorOptions> configureOptions) { if (configureOptions != null) { builder.Services .Configure(configureOptions); } builder.Services.AddTransient <IGenerateProvider>(serviceProvider => new GenerateProvider(serviceProvider)); return(builder.AddApiExplorer()); }
private static IMvcBuilder AddWebApi(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } IMvcCoreBuilder builder = services.AddMvcCore(); builder.AddJsonFormatters(); builder.AddApiExplorer(); builder.AddCors(); return(new MvcBuilder(builder.Services, builder.PartManager)); }
/// <summary> /// Adds WebApi 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 WebApi services.</returns> public static IMvcBuilder AddWebApi(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException("services"); } IMvcCoreBuilder mvcCoreBuilder = services.AddMvcCore(); mvcCoreBuilder.AddApiExplorer(); mvcCoreBuilder.AddAuthorization(); mvcCoreBuilder.AddFormatterMappings(); mvcCoreBuilder.AddDataAnnotations(); mvcCoreBuilder.AddJsonFormatters(); mvcCoreBuilder.AddCors(); //-MvcServiceCollectionExtensions.AddDefaultFrameworkParts(mvcCoreBuilder.PartManager); //-mvcCoreBuilder.AddViews(); //-mvcCoreBuilder.AddRazorViewEngine(); //-mvcCoreBuilder.AddRazorPages(); //-mvcCoreBuilder.AddCacheTagHelper(); return(new MvcBuilder(mvcCoreBuilder.Services, mvcCoreBuilder.PartManager)); }
public void ConfigureServices(IServiceCollection services) { services.AddResponseCompression(); services.AddCors(builder => builder.AddDefaultPolicy(policyBuilder => policyBuilder.AllowAnyOrigin())); IMvcCoreBuilder mvc = services.AddMvcCore(); mvc.AddApiExplorer(); mvc.SetCompatibilityVersion(CompatibilityVersion.Latest); mvc.AddFormatterMappings(); mvc.AddJsonFormatters(); mvc.AddJsonOptions( options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); options.SerializerSettings.Formatting = Formatting.Indented; } ); services.AddSignalR(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "Home assistant API", Description = $"Documentation for {Core.AssistantName} api endpoints.", Contact = new OpenApiContact() { Name = "Arun Prakash", Email = "*****@*****.**", Url = new Uri("https://github.com/SynergYFTW/HomeAssistant") }, License = new OpenApiLicense() { Name = "MIT License", Url = new Uri("https://github.com/SynergYFTW/HomeAssistant/blob/master/LICENSE") } }); }); }
public static IMvcCoreBuilder ConfigureSwaggerDependencies(this IMvcCoreBuilder builder) { return(builder.AddApiExplorer()); }