Starts in:
1 DAY
20 HRS
2 MIN
54 SEC
Starts in:
1 D
20 H
2 M
54 S
Open Closed

Remote Service Call on Domain Service #5577


User avatar
0
uyarbtrlp created

Hello,

I have a X module and I want to call one of its API on Y module in domain service. I want to use Synchronous Communication. Since the interface is in X.Application.Contracts and give the reference on Y.Application.Contracts, I am not able to use it in domain service. What is the best practice to call ABP module API in domain service?

Thanks


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

    Hi,

    You can use the static proxy system: https://docs.abp.io/en/abp/latest/API/Static-CSharp-API-Clients

    With Contracts generate all the classes/enums/other types in the client side (including application service interfaces) , This is also the default behavior of the generate-proxy command.

  • User Avatar
    0
    uyarbtrlp created

    If I understand it correctly, I need to add X.HttpApi.Client reference to Y.Domain. If the answer is yes, I have two questions:

    • Is it best practice to consume X module API on domain layer by referencing X.HttpApi.Client?
    • If it is not the best practice, should we call remote service on application layer by referencing X.Application.Contracts to Y.Application.Contracts?
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    I need to add X.HttpApi.Client reference to Y.Domain

    No, you don't need. you can generate proxy scripts in any project(even domain project).

    For example:

    Other steps are needed:

    • https://docs.abp.io/en/abp/latest/API/Static-CSharp-API-Clients#client-proxy-generation
    • Configure virtual file system
    • Set *generate-proxy.json file as an embedded file

    Is it best practice to consume X module API on domain layer by referencing X.HttpApi.Client?

    yes, this is not the best practice.

    If it is not the best practice, should we call remote service on application layer by referencing X.Application.Contracts to Y.Application.Contracts?

    Calling the remote service essentially uses Httpclient to send HTTP requests, You can use them at the domain layer or application layer, but you need to care about the dependencies between modules. you can generate static proxy scripts for domain project, everything required class interface and DTO have been generated locally, and you don't need the module reference.

  • User Avatar
    0
    uyarbtrlp created

    Okay, I got it. Besides its functionality, we don't want to generate the proxy scripts when every time code changes. When I examine here, we think that X ABP module is an external API and Y module shouldn't work without X module service (at least on some business logics). We know that there is a dependency issue. Let's say that I have a business logic that should run with X module API and I need to call it in domain service. I think Y.Domain like a client application and we can reference HttpApi.Client layer on Y.Domain layer since we run a business logic by using X module API.

    Do we violate the rules in terms of DDD by giving the X.HttpApi.Client reference to Y.Domain or is it a basically dependency issue that we should think about?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Do we violate the rules in terms of DDD by giving the X.HttpApi.Client reference to Y.Domain or is it a basically dependency issue that we should think about?

    This violates the rules, generating a static proxy is the recommended way

  • User Avatar
    0
    uyarbtrlp created

    Okay. Thanks for suggestions

  • User Avatar
    0
    uyarbtrlp created

    Hello again,

    When I run the command abp generate-proxy -t csharp -u http://localhost:53929/ -m fileManagement in domain layer, I can see that files generated But the project gives compile error since there are missing packages regarding application service. For example:

    I guess adding the Volo.Abp.Application.Services package is not a right way to do it. How to resolve that?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    You need to install the Volo.Abp.Application.Services package, this is the only way.

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