What are the pros/cons of choosing between static and instance data access classes in a web app?

前端 未结 4 1125
清歌不尽
清歌不尽 2021-02-05 14:05

I\'ve read several other questions on this topic (here, here, and here), but have yet to see a great answer. I\'ve developed my fair share of data access layers before and perso

4条回答
  •  攒了一身酷
    2021-02-05 14:09

    For me the main reason is that I don't need to keep the state of that DAL object. The state of the objects it uses don't span the scope of the method they are embeded. This way why would you keep multiple instances of an object, if they are all the same?

    With the latest versions of the ADO.NET, seems to be best practice to create and destroy the connection to the database within the scope of your call, and let the ConnectionPool take care of the whole connection reusability issue anyway.

    Again with the latest versions of the .NET Framework, TransactionScope (which would be one reason to manage your connections yourself) move up to the business level, which allow you to join multiple calls to the DAL within the same Scope.

    So I can't see a compeling case to create and destroy (or cache) instances of the DAL.

提交回复
热议问题