Refactored.

pull/96/head
Halil İbrahim Kalkan 8 years ago
parent 4be2cd2d46
commit cff53ca466

@ -38,7 +38,8 @@ namespace Volo.Abp.AspNetCore.Mvc
return false;
}
var configuration = _application.ServiceProvider.GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>().Value.ControllerAssemblySettings.GetSettingOrNull(type);
//TODO: Move this to a lazy loaded field for efficiency.
var configuration = _application.ServiceProvider.GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>().Value.AppServiceControllers.ControllerAssemblySettings.GetSettingOrNull(type);
return configuration != null && configuration.TypePredicate(type);
}
}

@ -106,7 +106,7 @@ namespace Volo.Abp.AspNetCore.Mvc
protected virtual bool CanUseFormBodyBinding(ActionModel action, ParameterModel parameter)
{
if (_options.FormBodyBindingIgnoredTypes.Any(t => t.IsAssignableFrom(parameter.ParameterInfo.ParameterType)))
if (_options.AppServiceControllers.FormBodyBindingIgnoredTypes.Any(t => t.IsAssignableFrom(parameter.ParameterInfo.ParameterType)))
{
return false;
}
@ -251,7 +251,7 @@ namespace Volo.Abp.AspNetCore.Mvc
[CanBeNull]
protected virtual AbpControllerAssemblySetting GetControllerSettingOrNull(Type controllerType)
{
return _options.ControllerAssemblySettings.GetSettingOrNull(controllerType);
return _options.AppServiceControllers.ControllerAssemblySettings.GetSettingOrNull(controllerType);
}
protected virtual AttributeRouteModel CreateAbpServiceAttributeRouteModel(string moduleName, string controllerName, ActionModel action, string httpMethod)

@ -97,6 +97,7 @@ namespace Volo.Abp.AspNetCore.Mvc
.ServiceProvider
.GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>()
.Value
.AppServiceControllers
.ControllerAssemblySettings
.Select(s => s.Assembly)
.Distinct();

@ -7,11 +7,20 @@ namespace Volo.Abp.AspNetCore.Mvc
{
public class AbpAspNetCoreMvcOptions
{
//TODO: Group into a class since they are related.
public AppServiceControllerOptions AppServiceControllers { get; }
public AbpAspNetCoreMvcOptions()
{
AppServiceControllers = new AppServiceControllerOptions();
}
}
public class AppServiceControllerOptions
{
public ControllerAssemblySettingList ControllerAssemblySettings { get; }
public List<Type> FormBodyBindingIgnoredTypes { get; }
public AbpAspNetCoreMvcOptions()
public AppServiceControllerOptions()
{
ControllerAssemblySettings = new ControllerAssemblySettingList();
FormBodyBindingIgnoredTypes = new List<Type>
@ -20,7 +29,7 @@ namespace Volo.Abp.AspNetCore.Mvc
};
}
public AbpControllerAssemblySettingBuilder CreateControllersForAppServices(
public AbpControllerAssemblySettingBuilder CreateFor(
Assembly assembly,
string moduleName = AbpControllerAssemblySetting.DefaultServiceModuleName,
bool useConventionalHttpVerbs = true)

@ -24,7 +24,7 @@ namespace Volo.Abp.AspNetCore.App
services.Configure<AbpAspNetCoreMvcOptions>(options =>
{
options.CreateControllersForAppServices(typeof(TestAppModule).Assembly);
options.AppServiceControllers.CreateFor(typeof(TestAppModule).Assembly);
});
services.AddAssemblyOf<AppModule>();

@ -34,7 +34,6 @@ namespace Volo.Abp.AspNetCore.Mvc
[Fact]
public async Task GetAll_Test()
{
//Ideally should be [GET] /api/app/people OK!
var result = await GetResponseAsObjectAsync<ListResultDto<PersonDto>>("/api/app/people");
result.Items.Count.ShouldBeGreaterThan(0);
}
@ -44,7 +43,6 @@ namespace Volo.Abp.AspNetCore.Mvc
{
var firstPerson = _personRepository.GetList().First();
//Ideally should be [GET] /api/app/people/{id} OK!
var result = await GetResponseAsObjectAsync<PersonDto>($"/api/app/people/{firstPerson.Id}");
result.Name.ShouldBe(firstPerson.Name);
}
@ -54,7 +52,6 @@ namespace Volo.Abp.AspNetCore.Mvc
{
var firstPerson = _personRepository.GetList().First();
//Ideally should be [DELETE] /api/app/people/{id} OK!
await Client.DeleteAsync($"/api/app/people/{firstPerson.Id}");
(await _personRepository.FindAsync(firstPerson.Id)).ShouldBeNull();
@ -67,7 +64,6 @@ namespace Volo.Abp.AspNetCore.Mvc
var postData = _jsonSerializer.Serialize(new PersonDto {Name = "John", Age = 33});
//Ideally should be [POST] /api/app/people OK!
var response = await Client.PostAsync(
"/api/app/people",
new StringContent(postData, Encoding.UTF8, "application/json")
@ -100,7 +96,6 @@ namespace Volo.Abp.AspNetCore.Mvc
//Act
//Ideally should be [PUT] /api/app/people/{id} OK!
var response = await Client.PutAsync(
$"/api/app/people/{updateDto.Id}",
new StringContent(putData, Encoding.UTF8, "application/json")
@ -136,7 +131,7 @@ namespace Volo.Abp.AspNetCore.Mvc
//Ideally should be [POST] /api/people/{id}/phones
var response = await Client.PostAsync(
$"/api/app/people/{personToAddNewPhone.Id}/Phone",
$"/api/app/people/{personToAddNewPhone.Id}/phone",
new StringContent(postData, Encoding.UTF8, "application/json")
);

Loading…
Cancel
Save