English 中文(简体)
如何建立单一代码多数据库 ASP.NET SaaS 应用程序
原标题:How to setup single-code multiple-database ASP.NET SaaS application

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.

我猜我需要单独的网络. configgs 连接字符串 。 或者我应该建立一个单独的数据库, 存储所有连接字符串和任何应用程序级别变量/ 内容 。 最后, 我希望能够实现这一供给的自动化( 如果使用允许的话 ) 。

是否有任何文章或文章可以让我指出如何用步骤来建立这个系统? 我找不到我所寻求的东西。

最佳回答

从技术上讲,这很简单。我们这样做多年。虽然我们使用不同的公约(my. domain.com/cust1 , my.domain.com/cust2 +url重写),但这并没有改变任何东西。

这就是你要做的。您创建了一个连接字符串提供者的抽象规格 :

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

然后提供您想要的任何执行, 如 :

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

并用某种方式将您的界面映射到执行上(例如,使用您选择的 IoC 容器)。

这使您有机会在部署期间配置提供者,例如,开发商可以使用一个提供者(从文件读取连接字符串),生产环境中可以使用另一个提供者(从易于提供的数据库读取连接字符串)。

如果你还有其他问题,请随意提问。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签