diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceControllerFeatureProvider.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceControllerFeatureProvider.cs index 1ef53867b6..284ffe8401 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceControllerFeatureProvider.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceControllerFeatureProvider.cs @@ -38,7 +38,8 @@ namespace Volo.Abp.AspNetCore.Mvc return false; } - var configuration = _application.ServiceProvider.GetRequiredService>().Value.ControllerAssemblySettings.GetSettingOrNull(type); + //TODO: Move this to a lazy loaded field for efficiency. + var configuration = _application.ServiceProvider.GetRequiredService>().Value.AppServiceControllers.ControllerAssemblySettings.GetSettingOrNull(type); return configuration != null && configuration.TypePredicate(type); } } diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs index da234bb474..f12e6388af 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs @@ -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) diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index dd5c302b5d..ac7804ceb3 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -97,6 +97,7 @@ namespace Volo.Abp.AspNetCore.Mvc .ServiceProvider .GetRequiredService>() .Value + .AppServiceControllers .ControllerAssemblySettings .Select(s => s.Assembly) .Distinct(); diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs index 0b962f8f13..ec9ee7a1d7 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs @@ -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 FormBodyBindingIgnoredTypes { get; } - public AbpAspNetCoreMvcOptions() + public AppServiceControllerOptions() { ControllerAssemblySettings = new ControllerAssemblySettingList(); FormBodyBindingIgnoredTypes = new List @@ -20,7 +29,7 @@ namespace Volo.Abp.AspNetCore.Mvc }; } - public AbpControllerAssemblySettingBuilder CreateControllersForAppServices( + public AbpControllerAssemblySettingBuilder CreateFor( Assembly assembly, string moduleName = AbpControllerAssemblySetting.DefaultServiceModuleName, bool useConventionalHttpVerbs = true) diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/AppModule.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/AppModule.cs index 297a5ed134..8cb8a2c903 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/AppModule.cs +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/AppModule.cs @@ -24,7 +24,7 @@ namespace Volo.Abp.AspNetCore.App services.Configure(options => { - options.CreateControllersForAppServices(typeof(TestAppModule).Assembly); + options.AppServiceControllers.CreateFor(typeof(TestAppModule).Assembly); }); services.AddAssemblyOf(); diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs index b8b1739ec4..28b5143e17 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs @@ -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>("/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($"/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") );