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)
-
0
-
0
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?
-
0
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.
-
0
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?
-
0
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
-
0
Okay. Thanks for suggestions
-
0
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? -
0
You need to install the
Volo.Abp.Application.Services
package, this is the only way.