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.ControllerPostfixes = options.RemoveControllerPostfixes; AppConsts.ActionPostfixes = options.RemoveActionPostfixes; AppConsts.FormBodyBindingIgnoredTypes = options.FormBodyBindingIgnoredTypes; AppConsts.GetRestFulActionName = options.GetRestFulActionName; AppConsts.AssemblyDynamicWebApiOptions = options.AssemblyDynamicWebApiOptions; 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()); }); return(services); }