I've created a report module and need to use this module in multiple microservices. In this module, I have some pages with following controllers
namespace MZH.MHIBS.Report.Controllers
{
[RemoteService(Name = ReportRemoteServiceConsts.RemoteServiceName)]
[Area(ReportRemoteServiceConsts.ModuleName)]
[Route("api/report/report-item")]
public class ReportItemController : ReportController, IReportItemAppService
{
protected IReportItemAppService ReportItemAppService { get; }
public ReportItemController(IReportItemAppService reportItemAppService)
{
ReportItemAppService = reportItemAppService;
}
[HttpPost]
[Route("batch-update")]
public Task BatchUpdateAsync(List<DXBatchUpdate> changes)
{
return ReportItemAppService.BatchUpdateAsync(changes);
}
[HttpGet]
public Task<LoadResult> GetListAsync(DataSourceLoadOptionsCustomized options)
{
return ReportItemAppService.GetListAsync(options);
}
}
}
Each microservice use different database. When using this module, each microservice will have the same tables. But I don't know how to separate the route of controllers for each microservice. Please help.
6 Answer(s)
-
0
You can use different connectionstrings for a specific module. Let say your Reporting module db conext has this attribute:
[ConnectionStringName("Reporting")] public class ReportingDbContext : AbpDbContext<ReportingDbContext> // ...
Then you can define this Reporting connectionstring the exactly same for each microservice, so they can use common database only for your specific module.
"ConnectionStrings": { "Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=BookStore;Trusted_Connection=True;TrustServerCertificate=true", "Reporting": "Server=(LocalDb)\\MSSQLLocalDB;Database=BookStore_Reporting;Trusted_Connection=True;TrustServerCertificate=true" },
-
0
Hi,
Thanks for your answer but you misunderstand my question. I have a ReportModule which have following tables: ReportItem, ReportType, ReportStructure and each table has a screen to maintain data. These screens use example controller above with the static Route attribute at the top of the controller
[Route("api/report/report-item")]
.Now I have 2 services: ServiceA and ServiceB use this module and different databases (ServiceAData, ServiceBData). These services will have the same 3 above tables in each database. I separated this point OK.
But my question is about the screens of the module, because 2 services use the same screens to maintain data just save into different databases. How to separated the route attribute of the controller for each service?
For example, when adding this module to ServiceA the route attribute will transform to
[Route("api/service-a/report/report-item")]
and[Route("api/service-b/report/report-item")]
for ServiceB.Because if I keep the route the same, I can't configure route in YARP. It will always point to one controller and therefore save data into one database.
-
0
Hi,
Any update on this issue?
-
0
Hello,
I recommend that you design the pages in the module as a component and set the route as a parameter of the component. You can then call this component with different routes on the relevant pages on the UI host side.
The method I suggest actually corresponds to the second method in the picture and you will have a more reusable UI.
Thanks.
-
0
Hi,
Thank for your suggestion.
Is there any way to change the name of javascript function when it is dynamically generated at runtime.
For example: In report module I have aReportItemAppService
in namespaceMZH.MHIBS.Report
withGetList
method. I add this module into AMLReportService after running, the javascript code will be generated like this:abp.utils.createNamespace(window, 'mZH.mHIBS.report.reportItems.reportItem'); mZH.mHIBS.report.reportItems.reportItem.getList = function(options, permission, ajaxParams) { return abp.ajax($.extend(true, { url: abp.appPath + 'api/aml-report-service/report-item' + abp.utils.buildQueryString(...) + '', type: 'GET' }, ajaxParams)); };
Now, if I use this module in CICReportService, the javascript code will be generated the same. I can change the API
api/aml-report-service/report-item
andapi/cic-report-service/report-item
but the name of javascript function still the same. How to change it. -
0
Hi,
Thank for your suggestion.
Is there any way to change the name of javascript function when it is dynamically generated at runtime.
For example: In report module I have aReportItemAppService
in namespaceMZH.MHIBS.Report
withGetList
method. I add this module into AMLReportService after running, the javascript code will be generated like this:abp.utils.createNamespace(window, 'mZH.mHIBS.report.reportItems.reportItem'); mZH.mHIBS.report.reportItems.reportItem.getList = function(options, permission, ajaxParams) { return abp.ajax($.extend(true, { url: abp.appPath + 'api/aml-report-service/report-item' + abp.utils.buildQueryString(...) + '', type: 'GET' }, ajaxParams)); };
Now, if I use this module in CICReportService, the javascript code will be generated the same. I can change the API
api/aml-report-service/report-item
andapi/cic-report-service/report-item
but the name of javascript function still the same. How to change it.Unfortunately, there is no support for that, and the dynamic JS API client proxy is generated by method naming convention.
Regards.