Skip to content

Commit

Permalink
#1187: Allow to configure every controllermodel for application servi…
Browse files Browse the repository at this point in the history
…ces.
  • Loading branch information
hikalkan committed Sep 19, 2016
1 parent aae44fd commit b245e54
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.ApplicationModels;

namespace Abp.AspNetCore.Configuration
{
Expand All @@ -18,12 +19,16 @@ public class AbpControllerAssemblySetting

public Func<Type, bool> TypePredicate { get; set; }

public Action<ControllerModel> ControllerModelConfigurer { get; set; }

public AbpControllerAssemblySetting(string moduleName, Assembly assembly, bool useConventionalHttpVerbs)
{
ModuleName = moduleName;
Assembly = assembly;
UseConventionalHttpVerbs = useConventionalHttpVerbs;

TypePredicate = type => true;
ControllerModelConfigurer = controller => { };
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using Microsoft.AspNetCore.Mvc.ApplicationModels;

namespace Abp.AspNetCore.Configuration
{
public class AbpControllerAssemblySettingBuilder: IAbpControllerAssemblySettingBuilder
public class AbpControllerAssemblySettingBuilder : IAbpControllerAssemblySettingBuilder
{
private readonly AbpControllerAssemblySetting _setting;

Expand All @@ -16,5 +17,11 @@ public AbpControllerAssemblySettingBuilder Where(Func<Type, bool> predicate)
_setting.TypePredicate = predicate;
return this;
}

public AbpControllerAssemblySettingBuilder ConfigureControllerModel(Action<ControllerModel> configurer)
{
_setting.ControllerModelConfigurer = configurer;
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;

namespace Abp.AspNetCore.Configuration
{
public class ControllerAssemblySettingList : List<AbpControllerAssemblySetting>
{
[CanBeNull]
public AbpControllerAssemblySetting GetSettingOrNull(Type controllerType)
{
return this.FirstOrDefault(controllerSetting => controllerSetting.Assembly == controllerType.Assembly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public interface IAbpAspNetCoreConfiguration
bool SetNoCacheForAjaxResponses { get; set; }

AbpControllerAssemblySettingBuilder CreateControllersForAppServices(
Assembly assembly,
string moduleName = AbpControllerAssemblySetting.DefaultServiceModuleName,
bool useConventionalHttpVerbs = true);
Assembly assembly,
string moduleName = AbpControllerAssemblySetting.DefaultServiceModuleName,
bool useConventionalHttpVerbs = true
);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using Microsoft.AspNetCore.Mvc.ApplicationModels;

namespace Abp.AspNetCore.Configuration
{
public interface IAbpControllerAssemblySettingBuilder
{
AbpControllerAssemblySettingBuilder Where(Func<Type, bool> predicate);

AbpControllerAssemblySettingBuilder ConfigureControllerModel(Action<ControllerModel> configurer);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ public void Apply(ApplicationModel application)
foreach (var controller in application.Controllers)
{
var type = controller.ControllerType.AsType();
var configuration = GetControllerSettingOrNull(type);

if (typeof(IApplicationService).IsAssignableFrom(type))
{
controller.ControllerName = controller.ControllerName.RemovePostFix(ApplicationService.CommonPostfixes);
configuration?.ControllerModelConfigurer(controller);

var configuration = GetControllerSettingOrNull(controller.ControllerType.AsType());
ConfigureArea(controller, configuration);
ConfigureRemoteService(controller, configuration);
}
Expand All @@ -51,7 +52,6 @@ public void Apply(ApplicationModel application)
var remoteServiceAtt = ReflectionHelper.GetSingleAttributeOrDefault<RemoteServiceAttribute>(type);
if (remoteServiceAtt != null && remoteServiceAtt.IsEnabledFor(type))
{
var configuration = GetControllerSettingOrNull(controller.ControllerType.AsType());
ConfigureRemoteService(controller, configuration);
}
}
Expand Down Expand Up @@ -224,6 +224,7 @@ private string GetModuleNameOrDefault(Type controllerType)
AbpControllerAssemblySetting.DefaultServiceModuleName;
}

[CanBeNull]
private AbpControllerAssemblySetting GetControllerSettingOrNull(Type controllerType)
{
return _configuration.Value.ControllerAssemblySettings.GetSettingOrNull(controllerType);
Expand Down

0 comments on commit b245e54

Please sign in to comment.