public static IMvcCoreBuilder AddWebApiProxy(this IMvcCoreBuilder mvcBuilder, Action <WebApiProxyOptions> optionAction) { var option = new WebApiProxyOptions(); optionAction(option); foreach (var o in option.WebApiProxies) { var interfaceTypes = o.GetType().Assembly.GetTypes() .Where(x => x.IsInterface && x.GetMethods() .SelectMany(m => m.GetCustomAttributes(typeof(ApiActionAttribute), true)).Any()); foreach (var t in interfaceTypes) { mvcBuilder.AddMvcOptions(opt => { opt.Conventions.Add(new ControllerModelConvention(t)); opt.Conventions.Add(new ActionModelConvention(t)); opt.Conventions.Add(new ParameterModelConvention(t)); }); } mvcBuilder.ConfigureApplicationPartManager(manager => { var featureProvider = new ServiceControllerFeatureProvider(interfaceTypes); manager.FeatureProviders.Remove( manager.FeatureProviders.FirstOrDefault(x => x.GetType() == typeof(ControllerFeatureProvider))); manager.FeatureProviders.Add(featureProvider); }); ; } return(mvcBuilder); }
public static IMvcCoreBuilder AddWebApiProxyServer(this IMvcCoreBuilder mvcBuilder, Action <WebApiProxyOptions> optionAction) { AppDomain.CurrentDomain.UpdateExcutingAssemblies(); var option = new WebApiProxyOptions(); optionAction(option); foreach (var o in option.WebApiProxies) { var interfaceTypes = o.GetType().Assembly.GetTypes() .Where(x => x.IsInterface); foreach (var t in interfaceTypes) { mvcBuilder.AddMvcOptions(opt => { opt.Conventions.Add(new ControllerModelConvention(t)); opt.Conventions.Add(new ActionModelConvention(t)); opt.Conventions.Add(new ParameterModelConvention(t)); }); } mvcBuilder.ConfigureApplicationPartManager(manager => { var featureProvider = new ServiceControllerFeatureProvider(interfaceTypes); manager.FeatureProviders.Remove( manager.FeatureProviders.FirstOrDefault(x => x.GetType() == typeof(ControllerFeatureProvider))); manager.FeatureProviders.Add(featureProvider); }); ; } return(mvcBuilder); }
public static IMvcCoreBuilder AddWebApiProxyServer(this IMvcCoreBuilder mvcBuilder, Action <WebApiProxyOptions> optionAction) { var option = new WebApiProxyOptions(); optionAction(option); foreach (var inf in option.WebApiProxies.SelectMany(x => x.GetType().Assembly.GetTypes().Where(t => t.IsInterface))) { option.RegisteredServices.Add(new KeyValuePair <string, Type>("", inf)); } return(mvcBuilder.ConfigureInterfaces(option)); }
private static IMvcCoreBuilder ConfigureInterfaces(this IMvcCoreBuilder mvcBuilder, WebApiProxyOptions options) { foreach (var t in options.RegisteredServices.Select(x => x.Value)) { mvcBuilder.AddMvcOptions(opt => { opt.Conventions.Add(new ControllerModelConvention(t)); opt.Conventions.Add(new ActionModelConvention(t)); opt.Conventions.Add(new ParameterModelConvention(t)); }); } mvcBuilder.ConfigureApplicationPartManager(manager => { var featureProvider = new ServiceControllerFeatureProvider(options.RegisteredServices.Select(x => x.Value)); manager.FeatureProviders.Remove(manager.FeatureProviders.FirstOrDefault(x => x.GetType() == typeof(ControllerFeatureProvider))); manager.FeatureProviders.Add(featureProvider); }); return(mvcBuilder); }