开发者

Database Connection in ASP.NET Site - Should it be singleton implementation?

开发者 https://www.devze.com 2023-03-23 04:48 出处:网络
I am designing a typical ASP.NET site which will connect to database to retrieve and display data. Its a three tier logical implementation with database, middle and presentation layer.

I am designing a typical ASP.NET site which will connect to database to retrieve and display data. Its a three tier logical implementation with database, middle and presentation layer.

Should the class which creates a connection to the database be implemented as singleton ?

Does it mean that there will be always only one connection to the database ?

I have heard o开发者_开发技巧f connection pooling in ASP.NET. Isn't by making it singleton, we are ignoring this feature of ASP.NET ?


No. Let me be the first to say that the Database Connection shouldn't be a Singleton.

Instead, investigate the Unit of Work pattern. Each Unit of Work should have its own connection to the database.


A class which creates connections might be a singleton. But actual connection object should never be singeton.

0

精彩评论

暂无评论...
验证码 换一张
取 消