Open Closed

Share user data from module #2131


0
andmattia created

I try to understand how can I create a module where I need access data came from another.

Suppose to have a CRM module and E-Comm module. In CRM I create / admin customer on E-Com need to access to that data.

My question is realated to:

  1. if module CRM work with MSSQL and E-Com with MongoDb is it possibile?
  2. in terms of performance I need to use a SQL Statement if have more module on same DB arch I can exceute that query but if not on same DB, exist a way to sync data from different module?
  3. in case of use MongoDb can I use dynamic object to map object db?

9 Answer(s)
  • 0
    liangshiwei created
    Support Team

    Hi,

    if module CRM work with MSSQL and E-Com with MongoDb is it possibile?

    No problem, because modules are independent,you can deploy them separately.

    in terms of performance I need to use a SQL Statement if have more module on same DB arch I can exceute that query but if not on same DB, exist a way to sync data from different module?

    Module should be responsible for its database query, you should not access the database across modules. you should access the module data via HTTP API. see: https://docs.abp.io/en/abp/latest/API/Dynamic-CSharp-API-Clients

    in case of use MongoDb can I use dynamic object to map object db?

    There is no official solution, you can try search on google: https://www.google.com/search?q=mongodb+c#+dynamic+object But we do not recommend using dynamic objects.

    You can check the microservice template, It suits your case. https://docs.abp.io/en/commercial/latest/startup-templates/module/index

  • 0
    andmattia created

    Ok

    I agree that each module must be responsable of own data but how can I solve the simplest problem I need to show the own data module with owner user name for example. I think this challange is quite often in a lot of case.

    In single DB architecture I can add to EF the same table in that way I can achive the result the only problem/pitfall can be that POCO class must be shared but in 2 different DB arch how can I solve it? I my case if I store data for E-Comm module on MongoDb the only way is store all user data in the collaction for example but if my user update some data (es name or email) I need to brodcast this update to all module that has stored data in place of link it.

  • 0
    liangshiwei created
    Support Team

    Hi,

    You can get data from the module via Http API, ABP provided dynamic Http Api proxy system. you can call it like a local method.

    Or you can directly reference the data layer(.MongoDB or .EntityframeworkCore) project, so you can inject the repository to query data

  • 0
    andmattia created

    Hi

    I can not uderstand how can it solve the problem. If you look to the on semple ![image]

    I case some one need to now the user that create a post on blog module how can you get it? or product name? in the second case you can try to fix using same microservice but in the first. So how you can crate a table with 4 cols id, User Name, Blog Post title, creation data? Consider the option to show on Angualr query and export it on excel.

    (https://raw.githubusercontent.com/abpframework/abp/rel-4.4/docs/en/images/microservice-sample-diagram-3.png)

  • 0
    liangshiwei created
    Support Team

    Hi

    how can you get it? or product name?

    https://github.com/abpframework/abp/blob/dev/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUser.cs

    This is what we did, we have redundant user data in the blog module and synchronize data using distributed events.

    If you just want to get the product, you can try:

    public class BlogProductController : //....
    {
      private readonly IProductionAppService _productAppService;  // dynamic Http Api proxy
      
      public BlogProductController(//....)
       
      public async Task<Product> GetProductByName(string productName)
      {
         // will send a http request to product module.
         return await _productAppService.GetProductByName(productName)
      }
    }
    
  • 0
    andmattia created

    Hi

    Ok I completle agree about sync by events can you shere some details about that?

  • 0
    liangshiwei created
    Support Team

    Hi,

    We used distributed events: https://docs.abp.io/en/abp/latest/Distributed-Event-Bus

    You can check it: https://github.com/abpframework/abp/blob/dev/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUserSynchronizer.cs

  • 0
    andmattia created

    Any available example?

  • 0
    liangshiwei created
    Support Team

    Hi,

    Sorry I don't know what is available example mean, we have done it in the Blogging module and you can check the source code.