Click here to Skip to main content
15,904,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am about to start working on a really big project. Before i start, I would like to know the following...
When working with classes,would it be best to let every class manage its own MySQL connections or would passing the connections as arguments from one class to another be a better alternative? I noticed there's a bit of a trade-off so i just wanted to know what the best way to go would be.
Posted
Comments
Gautham Prabhu K 7-Nov-15 11:24am    
Most of the DB and DB API's pool the database connection implicitly and are very efficient. So unless you have very specific reason to control it yourself I would recommend not to do so.

So you can open connection anywhere in your class and do required operation and close when your done.

1 solution

First of all, why to let every class manage MySQL connection when they are not supposed to have knowledge of database. You should have separate layers of separate concerns. All the database kind stuffs should be done in a separate Data Access Layer. The business logic should be a separate layer.

There are various parameters to decide the right architecture and approach for your application. There is nothing like "..really a big project".

Believe me you have a huge task ahead (considering your question). You need to learn how to design Enterprise Applications.

Check these articles for further details-
Enterprise Application Architecture: Designing Applications and Services in .NET - Part I[^]
A Guide to Building Enterprise Applications on the .NET Framework[^]
Enterprise Solution Patterns Using Microsoft .NET[^]

Here is a book for reference-
Microsoft .NET - Architecting Applications for the Enterprise (Developer Reference)[^]

Hope, it helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900