/// <summary> /// Ctor /// </summary> /// <param name="serviceCollection">ServiceCollection</param> public DynamicControllerConvention(IServiceCollection serviceCollection) { _serviceCollection = serviceCollection; _dynamicControllerOptions = serviceCollection.GetService <DynamicControllerOptions>(); }
public static IServiceCollection AddDyanmicController(this IServiceCollection services, DynamicControllerOptions options = null) { var partManager = services.GetService <ApplicationPartManager>(); if (partManager == null) { throw new InvalidOperationException("请在AddMvc()方法后调用AddDynamicController()"); } partManager.FeatureProviders.Add(new DynamicControllerFeatureProvider()); if (options == null) { options = DynamicControllerOptions.Default; } services.AddSingleton(typeof(DynamicControllerOptions), options); services.Configure <MvcOptions>(o => { o.Conventions.Add(new DynamicControllerConvention(services)); }); return(services); }