There is a long habit here, where I work on the fact that the connection string lives in web.config, the Sql Connection object is created in the using block with this connection string and passed to the DataObjects constructor (using the CreateInstance method as the constructor is private). Something like that:
using(SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { DataObject foo = DataObject.CreateInstance(conn); foo.someProperty = "some value"; foo.Insert(); }
All this smells to me .. I don't know. Should the DataLayer class library be responsible for Connection objects and Connection strings? I would appreciate it to find out what others, or any good online articles about these design decisions are doing.
Please note that the projects we are working on are always Sql Servers, and this is unlikely to change. Thus, the factory and provider template are not what I need. It is more about where responsibility lies and where configuration parameters must be managed to work at the data level.
I like to code classes at my data access level, so they have one constructor that accepts IDbConnection as a parameter and the other a string (connection).
, SqlConnection, ( ), IDbConnection ( ) (, web.config) .
, , datalayer , . , , SQLConnection , .
, datalayer, DataInputs, , DataObjects. DataInput : ", DataObjects THAT, , , SQL-.
, " "? datalayer . (, , . , , (tm))
this "smell" is relative. if you are sure that you will associate this particular piece of code with SQL Server and the connection string string web.config, then this is completely normal. if you do not participate in such a connection, I agree that this is a smell of code and is undesirable.
Source: https://habr.com/ru/post/1698026/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1698021/java-swing-client-data-access-to-remote-database-ibatis&usg=ALkJrhhcGxDsPthzgaQC0haNE01rMEMGNQHow to include RSS feed in RSS? - pythonVisualBasic Month function malfunction - vb.netAttribute of attribute change by parameter - using Moq - c #Can I use ServicePointManager with a Webbrowser control? - c #Eclipse Whirlwind Tour? - eclipseThe default segment name in rails resource routing is ruby-on-railsLINQ to SQL Table Dependency - linqПроблема сериализации - c#What will be faster than Flash or Javascript? - javascriptAll Articles