Search code examples
c#aspnetboilerplate

How to build Web API remote services based on application project?


I am very new to ASP.NET Boilerplate.

It was said in the ASP.NET Core documentation that:

ASP.NET Boilerplate provides the infrastructure to create application services. If you want to expose your application services to remote clients as controllers (as previously done using dynamic web api), you can easily do that with a simple configuration in the PreInitialize method of your module.

Can you please explain the procedure clearly on how to expose the methods in my application project to remote clients?

For example in Acme.SimpleTaskApp, there is a method to list the tasks:

public async Task<ListResultDto<TaskListDto>> GetAll(GetAllTasksInput input)
{
    var tasks = await _taskRepository
        .GetAll()
        .Include(t => t.AssignedPerson)
        .WhereIf(input.State.HasValue, t => t.State == input.State.Value)
        .OrderByDescending(t => t.CreationTime)
        .ToListAsync();

    return new ListResultDto<TaskListDto>(
        ObjectMapper.Map<List<TaskListDto>>(tasks)
    );
}

How can I expose the GetAll method? And what would be the Get address for that method?

api/GetAll?

Thank you very much.


Solution

  • From the documentation on Application Services as Controllers for ASP.NET Core:

    Configuration.Modules.AbpAspNetCore()
         .CreateControllersForAppServices(
             typeof(AbpProjectNameApplicationModule).Assembly,
             moduleName: "app",
             useConventionalHttpVerbs: true
         );
    

    When an application service is converted to an MVC Controller, its default route will look like: /api/services/<module-name>/<service-name>/<method-name>.

    For example, if ProductAppService defines a Create method, its URL will be /api/services/app/product/create (assuming that the module name is 'app').