i need to write a library (dll) in c# to handle correctly multiple instances of DataContext.
This library must be written for a global using (web, console, etc..).
On a my old DB library, i create a type with private costructor, and a static property, for simplify my projects
An example:
public class DbClass
{
private DbClass() { }
private static DbClass instance;
public static DbClass Instance
{
get
{
if (DbClass.instance == null)
DbClass.instance = new DbClass();
return DbClass.instance;
}
}
}
An example of use:
public void Update()
{
DbClass.Instance.ExecuteSql("UPDATE Users SET IsUpdated = 'True'");
}
This class stored only a string (connectionString) into its static instance: no problems in web context, no problems in console context.
But i need to reuse this concept with linq-to-sql, by extending the DataContext type.
Any ideas?
EDIT:
By the first comment of Grant Thomas, i think my request is not explained good, and maybe my bad english not help..
I need to write a .Net Library (dll) to manage DB Data by a static DataContext Property:
this property must detect the current Context (web, windows MTA Thread, windows STA Thread)
and create/reuse instances of DataContext without throwing ThreadExceptions or others conflicts.
A sort of DataContextFactory...
Any comments/ideas was appreciated