Reducing the dependency of the Entity library library on app.config

I am looking for some tips on how to reduce the dependency of the Entity Framework library library on application files or web.config. My application contains an Entity Data ADO.NET data model.

I am currently referencing this library in a web project, but for this I have to add the connection string to the web.config web application before deployment.

Now I have a requirement to use a standalone DLL, and I can not change the parent project configuration files to include in my EF library.

What would be the best way to keep the connection string, but keep the integrity of my edmx and where should I refer?

+4
source share
2 answers
EntityConnectionStringBuilder builder = New EntityConnectionStringBuilder(); builder.Metadata = "res://*/Entities.VDMFinance.csdl|res://*/Entities.YourEntities.ssdl|res://*/Entities.YourEntities.msl"; builder.Provider = "System.Data.SqlClient"; builder.ProviderConnectionString = yourConnectionString; Dim dc As New YourEntities(builder.ConnectionString) dc.CommandTimeout = 0; 

You can initialize all your data contexts from a static factory that does this all the time. You can get the metadata and the provider from the original connection string, which is generated when objects are created.

+7
source

The configuration job, mainly web.config / app.config, is common to all .NET applications. It is used even by large products. Trying to avoid this does no good.

If you want your .dll to manage the connection string, it should read it from somewhere - perhaps from a custom configuration file with hard code in your library. After you download the connection string, you can pass it to the constructor of your ObjecContext as the @linkerro shown.

+3
source

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


All Articles