Pros and Cons of using Singleton Pattern in DAL

前端 未结 6 1589
感动是毒
感动是毒 2021-02-06 16:26

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

I would like to know the pros and cons and

6条回答
  •  梦如初夏
    2021-02-06 17:08

    I'm a bit uneasy about using singletons in the case of a DAL. What if I want to use more than one database backend. Perhaps I want to use MsSQL for invoices but Active Directory for Authentication. Or maybe I want to use MySQL for forum posts, but PostgreSQL for geo-clustering (more realistic for me, heh). Singleton Interfaces might make testing the database layers much more challenging when I can't pass a mock database connection to the test.

提交回复
热议问题