在DAL使用Singleton模式的优点和缺点 [英] Pros and Cons of using Singleton Pattern in DAL

查看:145
本文介绍了在DAL使用Singleton模式的优点和缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经要求使用单模式实现DAL,但我认为它很难池中的连接,使用transactions..etc

I have asked to use singleton pattern implemented DAL, but I think its difficult to pool the connections,use transactions..etc

我想知道的利弊和缺点也想知道池中的连接,因为这样可能对我开发的网站超过500个并发用户的最佳方式。

I would like to know the pros and cons and also would like to know the best way to pool the connections as there can be more than 500 concurrent users for the site I am developing.

数据库服务器是甲骨文10克。

DB Server is Oracle 10g.

DAL使用企业库3.1

DAL uses Enterprise library 3.1

推荐答案

单例模式对于DAL是伟大的 - 我在自己的企业Web应用程序使用(数百个用户和超过2000方法20单的一些班)。连接池是通过ado.net和SQL Server本身确实是最好的处理。如果你想有多种类型的后端服务器的,这不是一个问题。即使有一个单例模式,你可能要处理实际上是对数据库进行直接通话的具体内容(包括参数,文本/过程名称,凭据/连接字符串的所有传入)一个集中的数据访问类。

The singleton pattern is great for a DAL -- I use this in my own enterprise web application (hundreds of users and over 2,000 methods in 20-some singleton classes). The connection pooling is indeed handled best by ado.net and the sql server itself. If you are wanting to have multiple types of back-end server, that's not a problem. Even with a singleton pattern, you probably want a centralized data-access class that handles the specifics of actually making direct calls to the database (with parameters, text/procedure names, credentials/connection string all passed in).

在我的情况,在一个相当于1每种方法:1,在我的数据库中的存储过程。这基本上使每个存储过程的C#前端挂钩,使他们可以被称为几乎就像原生的C#代码,语法讲话。这使得该DAL调用非常简单。我因为SP的问题数量庞大的单身多。每个SP都有一个前缀,如Development_或Financial_或ORGANIZATION_或什么的。然后,我有对应于每个,像发展,财政,或组织一个单例类。因此,SP Organization_ViewData将在C#是一个名为组织的一个单独的类名为ViewData的方法。

In my situation, each method on a single corresponds 1:1 with a stored procedure in my database. This essentially makes a C# "front end" hook for each stored procedure, so that they can be called almost like native C# code, syntactically speaking. It makes calls to the DAL very straightforward. I have multiple singletons because of the massive number of SPs in question. Each SP has a prefix, like Development_, or Financial_, or Organization_ or whatever. Then I have a singleton class that corresponds to each, like Development, Financial, or Organization. So the sp Organization_ViewData would in C# be a method named ViewData on a singleton class named Organization.

这是干嘛呢,当然只是其中一种方法,但我发现这与多个开发人员,而且在过去六年大量的代码工作得很好。最主要的是,一致性是关键。如果前端程序员看你单身经纪商之一的方法的名称,应该告诉他们究竟往哪里去到数据库中结束。如果有问题,或者如果有人有公司通过代码进行搜索,试图去了解它,有一个必须做的少跟踪的方式。

That's just one way of doing it, of course, but I've found that to work very well with multiple developers and a large amount of code over the last six years. The main thing is that consistency is key. If a front-end programmer is looking at the name of a method on one of your singleton brokers, that should tell them exactly where it is going into the database end. That way if there's a problem, or if someone's having to search through code to try to understand it, there's less tracing that has to be done.

这篇关于在DAL使用Singleton模式的优点和缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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