Currently, I have a .NET solution that I am developing that includes several subprojects, including an ASP.NET MVC project. My model was divided into a separate assembly, because I need to use it from other other projects in the solution.
My model consists of an Entity Framework ADO.NET entity model. I decided to go with a singleton template for my model with the following code (SalsaEntities is the name of my entity model):
partial class SalsaEntities
{
private static SalsaEntities _instance = new SalsaEntities();
public static SalsaEntities Instance
{
get
{
return _instance;
}
}
}
Then I use SalsaEntities.Instance from my other assemblies. This works fine in the third project that I have, the Windows service, although I had to include the connection string in the App.Config project file.
, , SalsaEntities.Instance ASP.NET MVC. , Web.config , ...
<connectionStrings>
<add name="SalsaEntities" connectionString="metadata=res://*/SalsaModel.csdl|res://*/SalsaModel.ssdl|res://*/SalsaModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=localhost;Initial Catalog=DbSalsa;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
... :
, EntityClient, .
, Windows , , .
,
P.S.: , , , Visual Studio , . , .