禁用某些服务的动态 Web api

Lor*_*lix 0 aspnetboilerplate

我下载了 ASP Boilerplate 模板,并试图禁用某些动态 WebAPI 的创建。我阅读了https://aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API 上的文档, 但我找不到在模板中禁用它的位置。我正在使用 NET Core + Angular4 模板。

Alp*_*glu 7

您可以使用属性[RemoteService(false)]来禁用创建应用程序服务的动态 Web api。您也可以在应用程序服务的方法上使用此属性。

 [RemoteService(false)]
 public interface IRoleAppService : IAsyncCrudAppService<RoleDto, int, PagedResultRequestDto, CreateRoleDto, RoleDto>
 {
        Task<ListResultDto<PermissionDto>> GetAllPermissions();
 }
Run Code Online (Sandbox Code Playgroud)

https://aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API#enabledisable


虽然 [RemoteService] 是禁用它的最简单方法,但您可以使用以下代码进行高级操作。

Configuration.Modules.AbpWebApi().DynamicApiControllerBuilder
    .ForAll<IApplicationService>(Assembly.GetExecutingAssembly(), "app")
    .ForMethods(builder =>
    {
        if (builder.Method.IsDefined(typeof(MyIgnoreApiAttribute)))
        {
            builder.DontCreate = true;
        }
    })
    .Build();
Run Code Online (Sandbox Code Playgroud)