Open Closed

Can't see API when developing a module using the new command abp add-module Acme.Software.SimpleTask --new --add-to-solution-file #769


User avatar
0
learnabp created
  • ABP Framework version: 4.0.2
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Seperated (Angular): no
  • Exception message and stack trace:

API are not automatically generated

  • Steps to reproduce the issue:
  1. Run abp add-module Acme.Software.SimpleTask --new --add-to-solution-file
  2. Create a ITaskAppService with a simple method GetAll as follows under the folder call Tasks in the Application.Contract Project in the modules folder
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

namespace Acme.Software.SimpleTask.Tasks
{
    public interface ITaskAppService : IApplicationService
    {
        
        Task<ListResultDto<TaskDto>> GetAllAsync(GetAllTasksInput input);

    }
}
  1. Create the TaskAppService as follows under the folder called Tasks in the Application.Contract Project in the Modules Folder
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Acme.Software.SimpleTask.Tasks
{
    public class TaskAppService : SimpleTaskAppService, ITaskAppService
    {
        private readonly IRepository<Task, Guid> _taskRepository;

        public TaskAppService(IRepository<Task, Guid> taskRepository)
        {

            _taskRepository = taskRepository;

        }

        public async Task<ListResultDto<TaskDto>> GetAllAsync(GetAllTasksInput input)
        {

            var tasks = await AsyncExecuter.ToListAsync(_taskRepository
                                .WhereIf(input.State.HasValue, t => t.State == input.State.Value)
                                .OrderByDescending(t => t.CreationTime)
                                );

            return new ListResultDto<TaskDto>(ObjectMapper.Map<List<Task>, List<TaskDto>>(tasks));
                                
        }
    }
}
  1. Run the project and navigate to Swager can't see the GetAll API

Solution Structure is as follws


8 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You need create an ApiController, just like SampleController

  • User Avatar
    0
    learnabp created

    Why, ABP create them automatically right?? if i follow the BookStore Tutorial then it is all automatic no need to create API Controller

    If i have to create a APIController in what project ?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Why, ABP create them automatically right?? if i follow the BookStore Tutorial then it is all automatic no need to create API Controller

    Because the module template is different from the app template. It is microservice compatible

    If i have to create a APIController in what project ?

    In *.HttpApi project.

  • User Avatar
    0
    learnabp created

    hmmmm thats not good .... it would be good if that was documented somewhere

  • User Avatar
    0
    alper created
    Support Team Director

    module is a sub application and it shouldn't be decided to expose all appservices in the module.

  • User Avatar
    0
    learnabp created

    can you please explain this a little bit more, having explored the samples like the Blogging modules.

    I can't see a reason why the API have to be implemented in *.HTTPApi as they are all being implemented, so wouldn't it be better to just automagiclly create them ?

  • User Avatar
    0
    alper created
    Support Team Director

    Explained here https://docs.abp.io/en/abp/latest/Best-Practices/Module-Architecture

  • User Avatar
    0
    alper created
    Support Team Director

    When you create a monolithic application, then you can use the AppServices as WebAPIs. But in tier layout it's not available. This is a diagram of a sample microservice (tier).

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11