I was wondering what is the best way to pass context between classes. Should I use the ref parameter or just pass the context as a parameter? Preferred constructor, but in case of static method the best approach? That is, performance, security, design, etc. Is there success in passing context as a parameter? Are conflicts possible if different threads work on the context at the same time using links?
Main.cs
static void Main(string[] args)
{
var context = new MyEntities();
var myClass = new MyClass(context);
myClass.AddPerson();
Person.AddPerson(ref context);
}
Myclass.cs
public class MyClass
{
public void MyClass(MyEntities context) { }
public void AddPerson()
{
context.People.AddObject(new Person());
}
}
MySecondClass.cs
public partial class Person
{
public static AddPerson(ref MyEntities context)
{
}
}
wonea source
share