Open Closed

Using an App service *without* API/Controller in Tiered Solution #4590


User avatar
0
Talal created

Please help me understand these things:

  1. Since I have to make the API Controller inherit from the related service Interface; I feel my self forced to create an API endpoint for each App service call even if I do not intend to use them (I just leave it as unimplemented sometimes)

  2. Then in many cases and even if it's against what I want to do; whenever I inject the Interface of that service, instead of the SERVICE implementation in the Application project used, the Controller implementation is used. For example, the API is called, not the service directly when I am trying to have an action in the Web project for example when a button is clicked in behind the code (C#). It's weird that the C# app service called the CONTROLLER implementation of the Service interface instead of calling the Service directly using the Application project implementation. The image below if from the submit action of a button in WEB. It should not use the API but it is. It should use the service implementation from Application project directly instead of 2 bounces

  3. In a completely different issue: I find it odd the multi-tiered solution duplicates the /api/ functionality in the WEB url instead of the proper was of calling API url using tokens for example. I noticed that it does this to use the logged-in user auth cookie in the web app. In a tiered application, the API calls are done with JWT token and handles renewal of the tokens etc. I still can not figure out why the Web project is tightly married to the API. Something is off.

Thank you


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

    Hi

    For Tiered project it's required.

    The tiered solution is a front-end and back-end separation project.

    • MVC is the front-end
    • HttpApi.Host is the back-end

    The MVC project does not access the database directly(application, domain service). It accesses the backend via HTTP API.

    You can see the document:https://docs.abp.io/en/abp/latest/Startup-Templates/Application#tiered-structure

  • User Avatar
    0
    Talal created

    I do not believe using an App service is "Accessing the database directly" I need a modern application where I do not fuse the Web and API together. these 2 must be separated.

    I should be able to make the WEB project dumb.

    the JWT token is not really used for API calls instead the Web is tightly coupled with the web.

    The separation between:

    • API
    • Web
    • and Auth server

    seems wrong.

    Why do I have to rout my service calls through API when I a using the code-behine? I should be able to use a call to the Application service directly.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    I need a modern application where I do not fuse the Web and API together. these 2 must be separated.

    You can consider using the Angular UI or Blazor UI, they are completely separate.

    the JWT token is not really used for API calls instead the Web is tightly coupled with the web.

    No, the Web use C# client proxy: https://docs.abp.io/en/abp/latest/API/Static-CSharp-API-Clients to access the API and the JWT token used inside.

    I should be able to use a call to the Application service directly.

    However, this is by design, but there is no something blocking you, you can change it if you want.

    I do not believe using an App service is "Accessing the database directly"

    As you know, typically application services use repositories or domain services and they have the ability to access databases.

  • User Avatar
    0
    Talal created

    Can you explain / example; how to call the service directly from Web code-behind without using the API?

    I will look into using Angular.

    Thank you

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    As I said, typically application services use repositories or domain services and they have the ability to access databases.

    It is almost indistinguishable from non-tiered:

    • Remove ...HttpApiClientModule from WebModule
    • Remove AbpAspNetCoreMvcClientModule from WebModule
    • Remove AbpHttpClientWebModule from WebModule
    • Add ..Application reference to the Web project and add ..ApplicationModule to the WebModule
    • Add ..EntityFrameworkCoreModule reference to the Web project and add ..EntityFrameworkCoreModule to the WebModule
    • Configure Auto API controllers:
    Configure<AbpAspNetCoreMvcOptions>(options =>
    {
        options.ConventionalControllers.Create(typeof(MyProjectNameApplicationModule).Assembly);
    });
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09