Java DataSource equivalent in .net

In .net (in particular, C # really), is there an equivalent Java class DataSource? I'm used to creating a single DataSource (pool or without pooling) and passing it to objects that require creating new database connections. Useful in decoupling / addiction situations.

However, in .net, the SqlConnection instance is created from the pool if you use the same connection string . Does this mean that you have to pass the connection string (or the connection string builder) to the DAO class classes, just bypass one Connection object or create a new ConnectionProvider class like ??

eg,

class SomethingDao { DataSource dataSource; Something getSomething(int id) { connection = dataSource.GetConnection(); connection.CreateCommand(); ... etc } } 
+4
source share
1 answer

The corporate library will take care of all these details for you, so I recommend that you use it and following the code example given here:

http://msdn.microsoft.com/en-us/library/ff953187%28v=PandP.50%29.aspx

This link will help you step by step. An equivalent using Ent Lib will be a database class. It has all the code examples, so I will not repeat them here.

+1
source

Source: https://habr.com/ru/post/1345662/


All Articles