Browse Source

Rename modulename to RootPath.

pull/113/head
Halil İbrahim Kalkan 9 years ago
parent
commit
0767c8441b
  1. 6
      src/AbpDesk/AbpDesk.Web.Mvc/appsettings.Staging.json
  2. 53
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs
  3. 6
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpControllerAssemblySetting.cs
  4. 4
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AppServiceControllerOptions.cs
  5. 12
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs
  6. 6
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/UrlActionNameNormalizerContext.cs
  7. 12
      src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ApplicationApiDescriptionModel.cs
  8. 12
      src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs
  9. 10
      src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs
  10. 4
      src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/AbpIdentityHttpApiClientModule.cs

6
src/AbpDesk/AbpDesk.Web.Mvc/appsettings.Staging.json

@ -3,9 +3,9 @@
"Default": "Server=10.0.75.1;Database=AbpDesk;User=sa;Password=123qwe;", "Default": "Server=10.0.75.1;Database=AbpDesk;User=sa;Password=123qwe;",
"AbpDeskMongoBlog": "mongodb://outputs_mongodb_1:27017|AbpDeskBlog" "AbpDeskMongoBlog": "mongodb://outputs_mongodb_1:27017|AbpDeskBlog"
}, },
"AbpIdentity": { "RemoteServices": {
"HttpApiClient": { "AbpIdentity": {
"ApiUrlBase": "http://outputs_abpidentity_httpapihost_1/" "BaseUrl": "http://outputs_abpidentity_httpapihost_1/"
} }
} }
} }

53
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs

@ -55,21 +55,6 @@ namespace Volo.Abp.AspNetCore.Mvc
} }
} }
protected virtual void ConfigureArea(ControllerModel controller, [CanBeNull] AbpControllerAssemblySetting configuration)
{
if (configuration == null)
{
return;
}
if (controller.RouteValues.ContainsKey("area"))
{
return;
}
controller.RouteValues["area"] = configuration.ModuleName;
}
protected virtual void ConfigureRemoteService(ControllerModel controller, [CanBeNull] AbpControllerAssemblySetting configuration) protected virtual void ConfigureRemoteService(ControllerModel controller, [CanBeNull] AbpControllerAssemblySetting configuration)
{ {
ConfigureApiExplorer(controller); ConfigureApiExplorer(controller);
@ -189,35 +174,35 @@ namespace Volo.Abp.AspNetCore.Mvc
return; return;
} }
var moduleName = GetModuleNameOrDefault(controller.ControllerType.AsType()); var rootPath = GetRootPathOrDefault(controller.ControllerType.AsType());
foreach (var action in controller.Actions) foreach (var action in controller.Actions)
{ {
ConfigureSelector(moduleName, controller.ControllerName, action, configuration); ConfigureSelector(rootPath, controller.ControllerName, action, configuration);
} }
} }
protected virtual void ConfigureSelector(string moduleName, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration) protected virtual void ConfigureSelector(string rootPath, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration)
{ {
RemoveEmptySelectors(action.Selectors); RemoveEmptySelectors(action.Selectors);
if (!action.Selectors.Any()) if (!action.Selectors.Any())
{ {
AddAbpServiceSelector(moduleName, controllerName, action, configuration); AddAbpServiceSelector(rootPath, controllerName, action, configuration);
} }
else else
{ {
NormalizeSelectorRoutes(moduleName, controllerName, action); NormalizeSelectorRoutes(rootPath, controllerName, action);
} }
} }
protected virtual void AddAbpServiceSelector(string moduleName, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration) protected virtual void AddAbpServiceSelector(string rootPath, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration)
{ {
var httpMethod = SelectHttpMethod(action, configuration); var httpMethod = SelectHttpMethod(action, configuration);
var abpServiceSelectorModel = new SelectorModel var abpServiceSelectorModel = new SelectorModel
{ {
AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, httpMethod), AttributeRouteModel = CreateAbpServiceAttributeRouteModel(rootPath, controllerName, action, httpMethod),
ActionConstraints = { new HttpMethodActionConstraint(new[] { httpMethod }) } ActionConstraints = { new HttpMethodActionConstraint(new[] { httpMethod }) }
}; };
@ -229,22 +214,22 @@ namespace Volo.Abp.AspNetCore.Mvc
return HttpMethodHelper.GetConventionalVerbForMethodName(action.ActionName); return HttpMethodHelper.GetConventionalVerbForMethodName(action.ActionName);
} }
protected virtual void NormalizeSelectorRoutes(string moduleName, string controllerName, ActionModel action) protected virtual void NormalizeSelectorRoutes(string rootPath, string controllerName, ActionModel action)
{ {
foreach (var selector in action.Selectors) foreach (var selector in action.Selectors)
{ {
var httpMethod = selector.ActionConstraints.OfType<HttpMethodActionConstraint>().FirstOrDefault()?.HttpMethods?.FirstOrDefault(); var httpMethod = selector.ActionConstraints.OfType<HttpMethodActionConstraint>().FirstOrDefault()?.HttpMethods?.FirstOrDefault();
if (selector.AttributeRouteModel == null) if (selector.AttributeRouteModel == null)
{ {
selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, httpMethod); selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel(rootPath, controllerName, action, httpMethod);
} }
} }
} }
protected virtual string GetModuleNameOrDefault(Type controllerType) protected virtual string GetRootPathOrDefault(Type controllerType)
{ {
return GetControllerSettingOrNull(controllerType)?.ModuleName ?? return GetControllerSettingOrNull(controllerType)?.RootPath ??
ModuleApiDescriptionModel.DefaultModuleName; ModuleApiDescriptionModel.DefaultRootPath;
} }
[CanBeNull] [CanBeNull]
@ -253,16 +238,16 @@ namespace Volo.Abp.AspNetCore.Mvc
return _options.AppServiceControllers.ControllerAssemblySettings.GetSettingOrNull(controllerType); return _options.AppServiceControllers.ControllerAssemblySettings.GetSettingOrNull(controllerType);
} }
protected virtual AttributeRouteModel CreateAbpServiceAttributeRouteModel(string moduleName, string controllerName, ActionModel action, string httpMethod) protected virtual AttributeRouteModel CreateAbpServiceAttributeRouteModel(string rootPath, string controllerName, ActionModel action, string httpMethod)
{ {
var url = CalculateUrl(moduleName, controllerName, action, httpMethod); var url = CalculateUrl(rootPath, controllerName, action, httpMethod);
return new AttributeRouteModel(new RouteAttribute(url)); return new AttributeRouteModel(new RouteAttribute(url));
} }
protected virtual string CalculateUrl(string moduleName, string controllerName, ActionModel action, string httpMethod) protected virtual string CalculateUrl(string rootPath, string controllerName, ActionModel action, string httpMethod)
{ {
var url = $"api/{moduleName}/{controllerName}"; var url = $"api/{rootPath}/{controllerName}";
//Add {id} path if needed //Add {id} path if needed
if (action.Parameters.Any(p => p.ParameterName == "id")) if (action.Parameters.Any(p => p.ParameterName == "id"))
@ -271,7 +256,7 @@ namespace Volo.Abp.AspNetCore.Mvc
} }
//Add action name if needed //Add action name if needed
var actionNameInUrl = NormalizeUrlActionName(moduleName, controllerName, action, httpMethod); var actionNameInUrl = NormalizeUrlActionName(rootPath, controllerName, action, httpMethod);
if (!actionNameInUrl.IsNullOrEmpty()) if (!actionNameInUrl.IsNullOrEmpty())
{ {
url += $"/{actionNameInUrl}"; url += $"/{actionNameInUrl}";
@ -287,9 +272,9 @@ namespace Volo.Abp.AspNetCore.Mvc
return url; return url;
} }
protected virtual string NormalizeUrlActionName(string moduleName, string controllerName, ActionModel action, string httpMethod) protected virtual string NormalizeUrlActionName(string rootPath, string controllerName, ActionModel action, string httpMethod)
{ {
var context = new UrlActionNameNormalizerContext(moduleName, controllerName, action, httpMethod, action.ActionName); var context = new UrlActionNameNormalizerContext(rootPath, controllerName, action, httpMethod, action.ActionName);
foreach (var normalizer in _options.AppServiceControllers.UrlActionNameNormalizers) foreach (var normalizer in _options.AppServiceControllers.UrlActionNameNormalizers)
{ {

6
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpControllerAssemblySetting.cs

@ -8,16 +8,16 @@ namespace Volo.Abp.AspNetCore.Mvc
{ {
public Assembly Assembly { get; } public Assembly Assembly { get; }
public string ModuleName { get; } public string RootPath { get; }
public Func<Type, bool> TypePredicate { get; set; } public Func<Type, bool> TypePredicate { get; set; }
public Action<ControllerModel> ControllerModelConfigurer { get; set; } public Action<ControllerModel> ControllerModelConfigurer { get; set; }
public AbpControllerAssemblySetting(Assembly assembly, string moduleName) public AbpControllerAssemblySetting(Assembly assembly, string rootPath)
{ {
Assembly = assembly; Assembly = assembly;
ModuleName = moduleName; RootPath = rootPath;
TypePredicate = type => true; TypePredicate = type => true;
ControllerModelConfigurer = controller => { }; ControllerModelConfigurer = controller => { };

4
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AppServiceControllerOptions.cs

@ -29,9 +29,9 @@ namespace Volo.Abp.AspNetCore.Mvc
}; };
} }
public AbpControllerAssemblySettingBuilder CreateFor(Assembly assembly, string moduleName = ModuleApiDescriptionModel.DefaultModuleName) public AbpControllerAssemblySettingBuilder CreateFor(Assembly assembly, string rootPath = ModuleApiDescriptionModel.DefaultRootPath)
{ {
var setting = new AbpControllerAssemblySetting(assembly, moduleName); var setting = new AbpControllerAssemblySetting(assembly, rootPath);
ControllerAssemblySettings.Add(setting); ControllerAssemblySettings.Add(setting);
return new AbpControllerAssemblySettingBuilder(setting); return new AbpControllerAssemblySettingBuilder(setting);
} }

12
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs

@ -56,7 +56,7 @@ namespace Volo.Abp.AspNetCore.Mvc
{ {
var controllerType = apiDescription.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(); var controllerType = apiDescription.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType();
var moduleModel = model.GetOrAddModule(GetModuleName(controllerType)); var moduleModel = model.GetOrAddModule(GetRootPath(controllerType));
var controllerModel = moduleModel.GetOrAddController(GetControllerName(apiDescription), controllerType); var controllerModel = moduleModel.GetOrAddController(GetControllerName(apiDescription), controllerType);
@ -65,7 +65,7 @@ namespace Volo.Abp.AspNetCore.Mvc
var uniqueMethodName = GetUniqueActionName(method); var uniqueMethodName = GetUniqueActionName(method);
if (controllerModel.Actions.ContainsKey(uniqueMethodName)) if (controllerModel.Actions.ContainsKey(uniqueMethodName))
{ {
Logger.LogWarning($"Controller '{controllerModel.ControllerName}' contains more than one action with name '{uniqueMethodName}' for module '{moduleModel.Name}'. Ignored: " + method); Logger.LogWarning($"Controller '{controllerModel.ControllerName}' contains more than one action with name '{uniqueMethodName}' for module '{moduleModel.RootPath}'. Ignored: " + method);
return; return;
} }
@ -154,18 +154,18 @@ namespace Volo.Abp.AspNetCore.Mvc
return modelNameProvider.Name; return modelNameProvider.Name;
} }
private string GetModuleName(Type controllerType) private string GetRootPath(Type controllerType)
{ {
if (controllerType == null) if (controllerType == null)
{ {
return ModuleApiDescriptionModel.DefaultModuleName; return ModuleApiDescriptionModel.DefaultRootPath;
} }
foreach (var controllerSetting in _options.AppServiceControllers.ControllerAssemblySettings) foreach (var controllerSetting in _options.AppServiceControllers.ControllerAssemblySettings)
{ {
if (Equals(controllerType.Assembly, controllerSetting.Assembly)) if (Equals(controllerType.Assembly, controllerSetting.Assembly))
{ {
return controllerSetting.ModuleName; return controllerSetting.RootPath;
} }
} }
@ -175,7 +175,7 @@ namespace Volo.Abp.AspNetCore.Mvc
return areaAttr.RouteValue; return areaAttr.RouteValue;
} }
return ModuleApiDescriptionModel.DefaultModuleName; return ModuleApiDescriptionModel.DefaultRootPath;
} }
} }
} }

6
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/UrlActionNameNormalizerContext.cs

@ -4,7 +4,7 @@ namespace Volo.Abp.AspNetCore.Mvc
{ {
public class UrlActionNameNormalizerContext public class UrlActionNameNormalizerContext
{ {
public string ModuleName { get; } public string RootPath { get; }
public string ControllerName { get; } public string ControllerName { get; }
@ -14,9 +14,9 @@ namespace Volo.Abp.AspNetCore.Mvc
public string ActionNameInUrl { get; set; } public string ActionNameInUrl { get; set; }
public UrlActionNameNormalizerContext(string moduleName, string controllerName, ActionModel action, string httpMethod, string actionNameInUrl) public UrlActionNameNormalizerContext(string rootPath, string controllerName, ActionModel action, string httpMethod, string actionNameInUrl)
{ {
ModuleName = moduleName; RootPath = rootPath;
ControllerName = controllerName; ControllerName = controllerName;
Action = action; Action = action;
HttpMethod = httpMethod; HttpMethod = httpMethod;

12
src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ApplicationApiDescriptionModel.cs

@ -26,17 +26,17 @@ namespace Volo.Abp.Http.Modeling
public ModuleApiDescriptionModel AddModule(ModuleApiDescriptionModel module) public ModuleApiDescriptionModel AddModule(ModuleApiDescriptionModel module)
{ {
if (Modules.ContainsKey(module.Name)) if (Modules.ContainsKey(module.RootPath))
{ {
throw new AbpException("There is already a module with same name: " + module.Name); throw new AbpException("There is already a module with same root path: " + module.RootPath);
} }
return Modules[module.Name] = module; return Modules[module.RootPath] = module;
} }
public ModuleApiDescriptionModel GetOrAddModule(string name) public ModuleApiDescriptionModel GetOrAddModule(string rootPath)
{ {
return Modules.GetOrAdd(name, () => ModuleApiDescriptionModel.Create(name)); return Modules.GetOrAdd(rootPath, () => ModuleApiDescriptionModel.Create(rootPath));
} }
public ApplicationApiDescriptionModel CreateSubModel(string[] modules = null, string[] controllers = null, string[] actions = null) public ApplicationApiDescriptionModel CreateSubModel(string[] modules = null, string[] controllers = null, string[] actions = null)
@ -45,7 +45,7 @@ namespace Volo.Abp.Http.Modeling
foreach (var module in Modules.Values) foreach (var module in Modules.Values)
{ {
if (modules == null || modules.Contains(module.Name)) if (modules == null || modules.Contains(module.RootPath))
{ {
subModel.AddModule(module.CreateSubModel(controllers, actions)); subModel.AddModule(module.CreateSubModel(controllers, actions));
} }

12
src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs

@ -10,9 +10,9 @@ namespace Volo.Abp.Http.Modeling
/// <summary> /// <summary>
/// "app". /// "app".
/// </summary> /// </summary>
public const string DefaultModuleName = "app"; public const string DefaultRootPath = "app";
public string Name { get; set; } public string RootPath { get; set; }
public IDictionary<string, ControllerApiDescriptionModel> Controllers { get; set; } public IDictionary<string, ControllerApiDescriptionModel> Controllers { get; set; }
@ -21,11 +21,11 @@ namespace Volo.Abp.Http.Modeling
} }
public static ModuleApiDescriptionModel Create(string name) public static ModuleApiDescriptionModel Create(string rootPath)
{ {
return new ModuleApiDescriptionModel return new ModuleApiDescriptionModel
{ {
Name = name, RootPath = rootPath,
Controllers = new Dictionary<string, ControllerApiDescriptionModel>() Controllers = new Dictionary<string, ControllerApiDescriptionModel>()
}; };
} }
@ -34,7 +34,7 @@ namespace Volo.Abp.Http.Modeling
{ {
if (Controllers.ContainsKey(controller.ControllerName)) if (Controllers.ContainsKey(controller.ControllerName))
{ {
throw new AbpException($"There is already a controller with name: {controller.ControllerName} in module: {Name}"); throw new AbpException($"There is already a controller with name: {controller.ControllerName} in module: {RootPath}");
} }
return Controllers[controller.ControllerName] = controller; return Controllers[controller.ControllerName] = controller;
@ -47,7 +47,7 @@ namespace Volo.Abp.Http.Modeling
public ModuleApiDescriptionModel CreateSubModel(string[] controllers, string[] actions) public ModuleApiDescriptionModel CreateSubModel(string[] controllers, string[] actions)
{ {
var subModel = Create(Name); var subModel = Create(RootPath);
foreach (var controller in Controllers.Values) foreach (var controller in Controllers.Values)
{ {

10
src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs

@ -34,12 +34,12 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
private static void AddModuleScript(StringBuilder script, ModuleApiDescriptionModel module) private static void AddModuleScript(StringBuilder script, ModuleApiDescriptionModel module)
{ {
//TODO: Eleminate repeating module.Name.Replace("/", ".").ToCamelCase() ! //TODO: Eleminate repeating module.RootPath.Replace("/", ".").ToCamelCase() !
//TODO: Remove illegal chars (like '-') from module/controller names! //TODO: Remove illegal chars (like '-') from module/controller names!
script.AppendLine($"// module '{module.Name.ToCamelCase()}'"); script.AppendLine($"// module '{module.RootPath.ToCamelCase()}'");
script.AppendLine("(function(){"); script.AppendLine("(function(){");
script.AppendLine($"abp.utils.createNamespace(abp, 'services.{module.Name.Replace("/", ".").ToCamelCase()}');"); script.AppendLine($"abp.utils.createNamespace(abp, 'services.{module.RootPath.Replace("/", ".").ToCamelCase()}');");
foreach (var controller in module.Controllers.Values) foreach (var controller in module.Controllers.Values)
{ {
@ -57,7 +57,7 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
script.AppendLine(" (function(){"); script.AppendLine(" (function(){");
script.AppendLine(); script.AppendLine();
script.AppendLine($" abp.services.{module.Name.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()} = abp.services.{module.Name.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()} || {{}};"); script.AppendLine($" abp.services.{module.RootPath.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()} = abp.services.{module.RootPath.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()} || {{}};");
foreach (var action in controller.Actions.Values) foreach (var action in controller.Actions.Values)
{ {
@ -74,7 +74,7 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
var parameterList = ProxyScriptingJsFuncHelper.GenerateJsFuncParameterList(action, "ajaxParams"); var parameterList = ProxyScriptingJsFuncHelper.GenerateJsFuncParameterList(action, "ajaxParams");
script.AppendLine($" // action '{action.NameOnClass.ToCamelCase()}'"); script.AppendLine($" // action '{action.NameOnClass.ToCamelCase()}'");
script.AppendLine($" abp.services.{module.Name.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()}{ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(action.NameOnClass.ToCamelCase())} = function({parameterList}) {{"); script.AppendLine($" abp.services.{module.RootPath.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()}{ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(action.NameOnClass.ToCamelCase())} = function({parameterList}) {{");
script.AppendLine(" return abp.ajax($.extend(true, {"); script.AppendLine(" return abp.ajax($.extend(true, {");
AddAjaxCallParameters(script, controller, action); AddAjaxCallParameters(script, controller, action);

4
src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/AbpIdentityHttpApiClientModule.cs

@ -7,11 +7,13 @@ namespace Volo.Abp.Identity
[DependsOn(typeof(AbpIdentityApplicationContractsModule), typeof(AbpHttpClientModule))] [DependsOn(typeof(AbpIdentityApplicationContractsModule), typeof(AbpHttpClientModule))]
public class AbpIdentityHttpApiClientModule : AbpModule public class AbpIdentityHttpApiClientModule : AbpModule
{ {
public const string RemoteServiceName = "AbpIdentity";
public override void ConfigureServices(IServiceCollection services) public override void ConfigureServices(IServiceCollection services)
{ {
services.AddAssemblyOf<AbpIdentityHttpApiClientModule>(); services.AddAssemblyOf<AbpIdentityHttpApiClientModule>();
services.AddHttpClientProxies(typeof(AbpIdentityApplicationContractsModule).Assembly, "AbpIdentity"); services.AddHttpClientProxies(typeof(AbpIdentityApplicationContractsModule).Assembly, RemoteServiceName);
} }
} }
} }
Loading…
Cancel
Save