public static IServiceCollection AddDynamicWebApi(this IServiceCollection services, Action <DynamicWebApiOptions> optionsAction) { var dynamicWebApiOptions = new DynamicWebApiOptions(); optionsAction?.Invoke(dynamicWebApiOptions); return(AddDynamicWebApi(services, dynamicWebApiOptions)); }
/// <summary> /// Add Dynamic WebApi to Container /// </summary> /// <param name="services"></param> /// <param name="options">configuration</param> /// <returns></returns> public static IServiceCollection AddDynamicWebApi(this IServiceCollection services, DynamicWebApiOptions options) { if (options == null) { throw new ArgumentException(nameof(options)); } options.Valid(); AppConsts.DefaultAreaName = options.DefaultAreaName; AppConsts.DefaultHttpVerb = options.DefaultHttpVerb; AppConsts.DefaultApiPreFix = options.DefaultApiPreFix; AppConsts.CommonPostfixes = options.ApiRemovePostfixes; AppConsts.FormBodyBindingIgnoredTypes = options.FormBodyBindingIgnoredTypes; var partManager = services.GetSingletonInstanceOrNull <ApplicationPartManager>(); if (partManager == null) { throw new InvalidOperationException("\"AddDynamicWebApi\" must be after \"AddMvc\"."); } // Add a custom controller checker partManager.FeatureProviders.Add(new DynamicWebApiControllerFeatureProvider()); services.Configure <MvcOptions>(o => { // Register Controller Routing Information Converter o.Conventions.Add(new DynamicWebApiConvention(services)); }); return(services); }
public static IServiceCollection AddSwagger(this IServiceCollection services, IConfiguration configuration, DynamicWebApiOptions options) { services.AddSwaggerGen(c => { //to do xml c.SwaggerDoc("v1", new OpenApiInfo { Title = "接口", Version = "1" }); c.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{Directory.GetCurrentDirectory()}.xml"), true); c.DocumentFilter <SwaggerIgnoreFilter>(); c.UseInlineDefinitionsForEnums(); }); services.AddSwaggerGenNewtonsoftSupport(); return(services); }