Database Connection in ASP.NET Site - Should it be singleton implementation?
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.
精彩评论