private void AddAbpServiceSelector(string moduleName, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration) { var abpServiceSelectorModel = new SelectorModel { AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action) }; var verb = configuration?.UseConventionalHttpVerbs == true ? ProxyScriptingHelper.GetConventionalVerbForMethodName(action.ActionName) : ProxyScriptingHelper.DefaultHttpVerb; abpServiceSelectorModel.ActionConstraints.Add(new HttpMethodActionConstraint(new[] { verb })); action.Selectors.Add(abpServiceSelectorModel); }
public void Apply(ControllerModel controller) { if (controller.ControllerType.IsGenericType && controller.ControllerType.GetGenericTypeDefinition() == typeof(DynamicCrudAppService <, ,>)) { var entityType = controller.ControllerType.GenericTypeArguments[0]; var registrations = _shaConfig.Value.DynamicApplicationServiceRegistrations.Where(reg => reg.Assembly == entityType.Assembly).ToList(); if (registrations.Count > 1) { throw new NotSupportedException($"Multiple registration of dynamic entities are not supported. Assembly name: '{entityType.Assembly.FullName}', modules: {registrations.Select(r => r.ModuleName).Delimited(",")}"); } var registration = registrations.FirstOrDefault(); if (registration == null) { return; } var moduleName = registration.ModuleName ?? AbpControllerAssemblySetting.DefaultServiceModuleName; controller.ControllerName = MvcHelper.GetControllerName(controller.ControllerType); foreach (var action in controller.Actions) { var routeTemplate = $"api/services/{moduleName}/{controller.ControllerName}/{action.ActionName}"; foreach (var selector in action.Selectors) { if (!selector.ActionConstraints.OfType <HttpMethodActionConstraint>().Any()) { var httpMethod = ProxyScriptingHelper.GetConventionalVerbForMethodName(action.ActionName); selector.ActionConstraints.Add(new HttpMethodActionConstraint(new[] { httpMethod })); } if (selector.AttributeRouteModel == null) { selector.AttributeRouteModel = new AttributeRouteModel(new RouteAttribute(routeTemplate)); } } } } }
private void AddAbpServiceSelector(string moduleName, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration) { var abpServiceSelectorModel = new SelectorModel { AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action) }; //计算当前api地址的动作约束 //如果没有设置,则使用post, //否则通过方法名称计算:根据方法名开头是否包含诸如Get,Post等字符串来确定 var verb = configuration?.UseConventionalHttpVerbs == true ? ProxyScriptingHelper.GetConventionalVerbForMethodName(action.ActionName) : ProxyScriptingHelper.DefaultHttpVerb; //添加动作约束 abpServiceSelectorModel.ActionConstraints.Add(new HttpMethodActionConstraint(new[] { verb })); //给action的选择器增加api路径选择器 action.Selectors.Add(abpServiceSelectorModel); }
public override void PreInitialize() { Configuration.DefaultNameOrConnectionString = _appConfiguration.GetConnectionString( JPGZServiceConsts.ConnectionStringName ); //配置grpc Configuration.Modules.UseGrpcService(option => { option.GrpcBindAddress = _appConfiguration["Grpc:GrpcBindAddress"]; option.GrpcBindPort = int.Parse(_appConfiguration["Grpc:GrpcBindPort"]); }).AddRpcServiceAssembly(typeof(JPGZServiceApplicationModule).Assembly); //禁用redis缓存会自动使用内存缓存 if (bool.Parse(_appConfiguration["App:RedisCache:IsEnabled"])) { //使用redis作为缓存 Configuration.Caching.UseRedis(options => { options.ConnectionString = _appConfiguration["App:RedisCache:ConnectionString"]; options.DatabaseId = _appConfiguration.GetValue <int>("App:RedisCache:DatabaseId"); }); //配置redis的Cache过期时间 Configuration.Caching.Configure("mycache", cache => { //缓存滑动过期时间,时长应当根据数据的更新频率来设置 cache.DefaultSlidingExpireTime = TimeSpan.FromMinutes(10); }); } //其他缓存时间配置 Configuration.Caching.ConfigureAll(options => { options.Clear(); options.DefaultSlidingExpireTime = TimeSpan.FromMinutes(5); }); //使用配置管理器 Configuration.Settings.Providers.Add <ConfigSettingProvider>(); // Use database for language management //Configuration.Modules.Zero().LanguageManagement.EnableDbLocalization(); Configuration.Modules.AbpAspNetCore() .CreateControllersForAppServices( typeof(JPGZServiceApplicationModule).GetAssembly() ). /* 自定义路由格式, * 默认为/api/services/app/Controller.ControllerName/action.ActionName/*/ ConfigureControllerModel(model => { foreach (var action in model.Actions) { var verb = ProxyScriptingHelper.GetConventionalVerbForMethodName(action.ActionName); var constraint = new HttpMethodActionConstraint(new List <string> { verb }); foreach (var selector in action.Selectors) { selector.ActionConstraints.Add(constraint); selector.AttributeRouteModel = new AttributeRouteModel( new RouteAttribute( $"api/{action.Controller.ControllerName}/{action.ActionName}" ) ); } } });; ConfigureTokenAuth(); }
private string SelectHttpMethod(ActionModel action, AbpControllerAssemblySetting configuration) { return(configuration?.UseConventionalHttpVerbs == true ? ProxyScriptingHelper.GetConventionalVerbForMethodName(action.ActionName) : ProxyScriptingHelper.DefaultHttpVerb); }