mirror of https://github.com/abpframework/abp.git
11 changed files with 150 additions and 11 deletions
@ -0,0 +1,45 @@ |
|||
using System; |
|||
using System.Reflection; |
|||
using Microsoft.AspNetCore.Mvc.Controllers; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Http; |
|||
using Volo.Abp.Reflection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc |
|||
{ |
|||
/// <summary>
|
|||
/// Used to add application services as controller.
|
|||
/// </summary>
|
|||
public class AbpAppServiceControllerFeatureProvider : ControllerFeatureProvider |
|||
{ |
|||
private readonly IAbpApplication _application; |
|||
|
|||
public AbpAppServiceControllerFeatureProvider(IAbpApplication application) |
|||
{ |
|||
_application = application; |
|||
} |
|||
|
|||
protected override bool IsController(TypeInfo typeInfo) |
|||
{ |
|||
var type = typeInfo.AsType(); |
|||
|
|||
if (!typeof(IApplicationService).IsAssignableFrom(type) || |
|||
!typeInfo.IsPublic || typeInfo.IsAbstract || typeInfo.IsGenericType) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
var remoteServiceAttr = ReflectionHelper.GetSingleAttributeOrDefault<RemoteServiceAttribute>(typeInfo); |
|||
|
|||
if (remoteServiceAttr != null && !remoteServiceAttr.IsEnabledFor(type)) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
var configuration = _application.ServiceProvider.GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>().Value.ControllerAssemblySettings.GetSettingOrNull(type); |
|||
return configuration != null && configuration.TypePredicate(type); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using Shouldly; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.TestApp.Application; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc |
|||
{ |
|||
public class PersonAppService_Tests : AspNetCoreMvcTestBase |
|||
{ |
|||
[Fact] |
|||
public async Task GetAll_Test() |
|||
{ |
|||
var result = await GetResponseAsObjectAsync<ListResultDto<PersonDto>>("/api/services/app/person/GetAll"); |
|||
result.Items.Count.ShouldBeGreaterThan(0); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue