Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In
Continue with Google
Continue with Facebook
or use


Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here
Continue with Google
Continue with Facebook
or use


Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.


Have an account? Sign In Now

Sorry, you do not have a permission to ask a question, You must login to ask question.

Continue with Google
Continue with Facebook
or use


Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Stack Ask

Stack Ask Logo Stack Ask Logo

Stack Ask Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 5430
In Process
Thưởng Đặng Văn
  • 1
Thưởng Đặng VănBeginner
Asked: April 17, 20222022-04-17T07:13:57+00:00 2022-04-17T07:13:57+00:00In: .Netcore

Multiple tenant multiple database .net core

  • 1

Hi mọi người!

Em đang học thiết kế ứng dụng mô hình SaaS Applications. Em muốn làm mô hình dạng mỗi shop sẽ là 1 database riêng biết. Em cũng mới chuyển qua .net core nên có 1 số câu hỏi như sau mong mọi người giúp:

  1. Khi nhiều shop thì cách mình định danh shop đó như thế nào ạ?
  2. Khi mà làm mô hình thế thì cần tìm hiểu thêm về những vấn đề gì (ví dụ cân bằng tài server….). Cái này hệ thống lớn mới cần nhưng em cũng muốn tìm hiểu coi nó sẽ như thế nào

Mọi người ai có kinh nghiệm giải đáp giúp em ạ. Có cái ví dụ nào cho e thì càng tốt ạ. Em cảm ơn mọi người.

.net coremultiple tenant
  • 10 10 Answers
  • 100 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

10 Answers

  • Voted
  • Oldest
  • Recent
  1. tvd12 Enlightened
    2022-04-17T10:08:22+00:00Added an answer on April 17, 2022 at 10:08 am

    Câu hỏi này có vẻ không liên quan gì đến .netcore nhỉ.

    1. Khi có nhiều shop thì em sẽ thêm 1 trường vào các bảng liên quan đến shop, ví dụ:

    create table Shop {
      shopId,
      shopName
    }
    
    create table Product {
      productId,
      projectName,
      shopId
    }
    

    2. Hiện tại anh thấy đội DevOps đang dùng K8s để triển khai hệ thống lớn, em có thể tìm hiểu về K8s nhé, nó sẽ bao gồm việc cấu hình LB, quản lý và monitor hệ thống em ạ.

    • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
    • Thưởng Đặng Văn Beginner
      2022-04-18T02:09:48+00:00Replied to answer on April 18, 2022 at 2:09 am

      Dạ nếu em muốn chia mỗi shop 1 database riêng thì mình sẽ xử lý như thế nào a nhỉ.

      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report
  2. Nguyen Nam Teacher
    2022-04-17T14:42:14+00:00Added an answer on April 17, 2022 at 2:42 pm

    Mình thấy có bài này hướng dẫn config multiple DB with .net
    Using Multiple Databases in ASP.NET Core via Entity Framework Core (code-maze.com)

    Còn đối với bài toán của bạn thì theo mình nên thiết kế DB như của a tvd12 là hợp lý nhất rồi.

    • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
    • Thưởng Đặng Văn Beginner
      2022-04-18T02:14:00+00:00Replied to answer on April 18, 2022 at 2:14 am

      Dạ tại vì mình muốn tách biệt mỗi shop ra 1 db riêng biệt. Vì khi deploy cho khách dùng thì có thể shop đó sẽ thay đổi một số tính năng nào đó trong quá trình sử dụng. Thì mình sẽ dễ tách ra để phát triển thêm các tính năng mà shop yêu cầu ạ.

      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report
      • Nguyen Nam Teacher
        2022-04-18T02:44:59+00:00Replied to answer on April 18, 2022 at 2:44 am

        Như vậy theo mình thì cứ mỗi shop 1 DB riêng cũng được. Mỗi shop sẽ có 1 server riêng để deploy code cũng như DB.

        • 0
        • Share
          Share
          • Share on Facebook
          • Share on Twitter
          • Share on LinkedIn
          • Share on WhatsApp
          • Report
        • Thưởng Đặng Văn Beginner
          2022-04-18T02:58:53+00:00Replied to answer on April 18, 2022 at 2:58 am

          Dạ ý tưởng em là tất cả đều dùng chung 1 app nhưng db riêng. Thì khi shop nào có nhu cầu phát triển thêm thì sẽ tách riêng app và db.
          Em đang bị vướng chỗ này. Khi các shop ở các db riêng thì mỗi shop se có connection khác nhau. Mà connection của mình thường sẽ lấy ở trong appsetting.json.

          Thì e đang vướng chỗ từ khi shop login thì sẽ nhập tên shop sau đó sẽ lấy chuỗi kết nối này như thế nào để truy cập đúng db của shop đó.

          • 0
          • Share
            Share
            • Share on Facebook
            • Share on Twitter
            • Share on LinkedIn
            • Share on WhatsApp
            • Report
          • Nguyen Nam Teacher
            2022-04-18T03:41:24+00:00Replied to answer on April 18, 2022 at 3:41 am

            Theo mình thì nên làm như này.
            Trường hợp shop thuê nhưng không có yêu cầu gì thêm thì nên có 1 bảng shop rồi dùng shopID để liên kết với các bảng có liên quan.
            Trường hợp shop thuê có yêu cầu riêng thì mình cần tách riêng DB, code cũng như server riêng cho từng shop.

            Còn việc muốn dùng 1 app mà lại tách riêng từng DB thì mình chưa thấy bao giờ nhưng nếu muốn làm thì bạn cần phải làm 1 số việc như:
            + Có 1 service riêng để login, logout dùng chung 1 DB.
            + Cấu hình bằng tay cho tất cả connection của mỗi shop…
            Bạn thử tham khảo bài này xem có giúp được gì không?
            https://dejanstojanovic.net/aspnet/2020/november/accessing-multiple-databases-from-the-same-dbcontext-in-ef-core/

            • 1
            • Share
              Share
              • Share on Facebook
              • Share on Twitter
              • Share on LinkedIn
              • Share on WhatsApp
              • Report
  3. monkey Enlightened
    2022-04-18T03:34:53+00:00Added an answer on April 18, 2022 at 3:34 am

    Tiếp nối câu trả lời của anh:

    1. Anh chưa hiểu tại sao em lại phải làm như vậy, vì làm vậy quá phức tạp, việc sử dụng chung db sẽ đơn giản hơn nhiều
    2. Tuy nhiên nếu em thực sự bắt buộc phải tổ chức mỗi shop 1 db em có thể tham khảo cách này xem sao:

    API Gateway em có thể sử dụng RestAPI hoặc Grpc.

    Khi cần truy cập data của shop nào, ví dụ product thì api sẽ kiểu này: /api/v1/{shopName}/products

    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  4. Thưởng Đặng Văn Beginner
    2022-04-18T07:22:06+00:00Added an answer on April 18, 2022 at 7:22 am

    hi a @monkey :

    Mô hình em muốn làm như thế này. Như em có trình bày ở trên là do có thể rất nhiều shop họ sẽ có quy trình riêng. cái core chỉ là 1 phần thôi nên khi phát triển thêm cho các shop từ cái core đó. Nên em muốn tách db ra ngay từ đầu luôn.

    Em có đọc được bài này ngta làm nhiều connection trong appsetting. Em đang muốn đưa cái đó vào database luôn (khi ngta đăng ký shop). Nên chưa biết cách xử lý cái connection khi shop đăng nhập như thế nào:

    https://codewithmukesh.com/blog/multitenancy-in-aspnet-core/

     

     

     

     

    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
    • monkey Enlightened
      2022-04-18T09:55:26+00:00Replied to answer on April 18, 2022 at 9:55 am

      Hiện tại các thư viện .netcore anh thấy đang khởi tạo DatabaseContext rồi repository từ khi chạy server, nên em muốn chỉ khi tạo shop mới tạo DB thì khả năng cao em phải tìm 1 thư viện nào đó hỗ trợ việc tạo database context lazy init, anh mò mà chưa có thấy

      • 1
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

You must login to add an answer.

Continue with Google
Continue with Facebook
or use


Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 581
  • Answers 1k
  • Best Answers 63
  • Users 299
  • Popular
  • Answers
  • monkey

    [Deep Learning] Làm thế nào để xác định được cái ...

    • 16 Answers
  • Tú Trần Anh

    [Ezyfox Server] Unity game client không gửi được command khi ...

    • 12 Answers
  • monkey

    [Go] khi nào go func được gọi?

    • 10 Answers
  • Nguyễn Thái Sơn
    Nguyễn Thái Sơn added an answer em cảm ơn, vậy mỗi câu truy vấn luôn có… June 24, 2022 at 4:31 pm
  • tvd12
    tvd12 added an answer Việc chuyển này cũng có nhiều khó khăn là nó… June 24, 2022 at 3:08 pm
  • tvd12
    tvd12 added an answer 1. Vì socket là giữ kết nối nên em sẽ… June 24, 2022 at 3:02 pm

Related Questions

  • LarreyK

    Làm sao để chia room và giới hạn số lượng ...

    • 5 Answers
  • Nam Nguyen

    Giống và khác nhau giữa async await và multi thread ...

    • 3 Answers
  • Nguyen Nam

    Lấy giá trị của TextBox trước và sau sự kiện ...

    • 2 Answers

Top Members

tvd12

tvd12

  • 65 Questions
  • 1k Points
Enlightened
monkey

monkey

  • 91 Questions
  • 620 Points
Enlightened
Nguyễn Thái Sơn

Nguyễn Thái Sơn

  • 148 Questions
  • 229 Points
Professional

Trending Tags

.net core abstract class analytics android ansible anti-flooding apache poi api async asyncawait atomicboolean backend backend nestjs bash script batch bean big project binding bitcoin blockchain blog boot-nodes branch british buffered build bundle c# cache caching callback career career path cast centos chat cloud cloud reliability commit company content-disposition contract cors cosmos css database datasource datastructure decentralized exchange deep learning design-pattern devops dex distraction programing docker download draw.io du học dữ liệu lớn eclip editor employee english erc20 erc721 eth ethereum ethereum login extensions exyfox ezyfox ezyfox-boot ezyfox-server ezyfoxserver ezyhttp facebook fe flutter freetank french front-end frontend fullstack fulltextsearch future game game-box game-room game-server get git go golang google grapql grpc guide hazelcast hibernate hibernateconfig html http https index indexing integration-test intellij interface interview io ipfs isolate issue it java javacore java core javascript java spring javaw java web job jpa js json jsp & servlet jvm jwt kafka keep promise kerberos keycloak kotlin language languague library load-balancing log log4j log4j-core login lưu trữ machine learning macos math maven merge messaging metamask microservice model mongo msgpack multiple tenant multithread multithreading mysql n naming naming convention netcore netty nft nft game nio nodejs non-blocking io opensource optimize orm pagination pancakeswap panic pgpool phỏng vấn pointer postgresql pre programming promise push message android python python unicode question queue rabbitmq reactive reactjs reactjs download recyclerview redis request resource rest roadmap ropssten ropsten rust rxjava schedule search security server shift jis singleton sjis slack smart contract socket soft delete sosanh spring spring-boot-test spring-jpa spring aop spring boot springboot spring data jpa spring redis spring security springsecurity springwebflux mysql sql sql server sse stackask storage stream structure trong spring boot system environment variables thread threadjava thymeleaf totp tracking location unit test unity upload file vector view volatile vue vue cli web3 web3 client webpack websocket windows 11 winforms work zookeeper

Footer

Stack Ask

Stack Ask is where Developers Ask & Answers. It will help you resolve any questions and connect you with other people.

About Us

  • Meet The Team
  • About Us
  • Contact Us

Legal Stuff

  • Terms of Service
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2021 Stack Ask. All Rights Reserved
Powered by youngmonkeys.org