如何设置单code多数据库ASP.NET SaaS应用程序 [英] How to setup single-code multiple-database ASP.NET SaaS application

查看:117
本文介绍了如何设置单code多数据库ASP.NET SaaS应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个SaaS应用程序,我想保留单code碱基我有。我想是在单独的子域cust1.saascompany.com,cust2.saascompany.com等。
不过,我没有任何TenantID的,并会preFER多种原因留在为每个客户单独的数据库(主要之一是,它已经codeD的方式没有意义去改变它,直到使用认股权证)。该数据库具有其中的用户登录的会员。

我猜我需要连接字符串单独web.configs?或者我应该创建一个存储所有的连接字符串和任何应用程序级的变量/常量一个单独的数据库?最后,我想能够自动执行此配置(同样,当使用权证的话)。

是否有一些文章或帖子,任何人都可以点我就如何与步骤设置?我一直没能找到我要找的。

解决方案

从技术上说,这很简单。我们多年做到这一点。虽然我们使用不同的约定( my.domain.com/cust1 my.domain.com/cust2 加网址重写)这不会改变任何事情。

所以,这是你做了什么。您创建一个连接字符串提供者的抽象规范:

 公共接口ICustomerInformationProvider
{
    字符串GetConnectionString(字符串客户ID);
    ... //也许其他信息
}

那么你提供你想要喜欢的任何实现:

 公共类WebConfigCustomerInformationProvider:ICustomerInformationProvider {...}
公共类DatabaseConfigCustomerInformationProvider:ICustomerInformationProvider {...}
公共类XmlConfigCustomerInformationProvider:ICustomerInformationProvider {...}

和您的接口映射到实现某种方式(例如,使用你选择的IoC容器)。

这让你在部署过程中配置提供商,例如的机会,一个供应商可以通过开发者使用(读取文件的连接字符串),另一种在生产环境(读取数据库连接字符串,其中可以轻松调配)。

如果您有其他疑问,请随时问。

I am building a SaaS application and I would like to retain the single code base I have. I would like to be in separate sub-domains cust1.saascompany.com, cust2.saascompany.com, etc. However, I don't have any TenantID's and would prefer for multiple reasons to stay with separate databases for each customer (primary one is that it's already coded that way and doesn't make sense to change it until usage warrants). The database has the user login membership within it.

I'm guessing I would need separate web.configs for connection strings? Or should I create a separate database that stores all the connection strings and any application level variables/constants? Eventually, I would like to be able to automate this provisioning (again, when usage warrants it).

Are there some articles or posts that anyone can point me to regarding how to set this up with steps? I haven't been able to find what I'm looking for.

解决方案

Technically, this is simple. We do this for years. Although we use a different convention (my.domain.com/cust1, my.domain.com/cust2 plus url rewriting) this doesn't change anything.

So, this is what you do. You create an abstract specification of a connection string provider:

public interface ICustomerInformationProvider
{
    string GetConnectionString( string CustomerId );  
    ... // perhaps other information
}

then you provide any implementation you want like:

public class WebConfigCustomerInformationProvider : ICustomerInformationProvider { ... }
public class DatabaseConfigCustomerInformationProvider : ICustomerInformationProvider { ... }
public class XmlConfigCustomerInformationProvider : ICustomerInformationProvider { ... }

and you map your interface onto the implementation somehow (for example, using an IoC Container of your choice).

This gives you the chance to configure the provider during the deployment, for example, a one provider can be used by developers (reads connection strings from a file) and another one in the production environment (reads connection strings from a database which can be easily provisioned).

If you have other questions, feel free to ask.

这篇关于如何设置单code多数据库ASP.NET SaaS应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆