Reputation: 10332
I have a class that provide the CRUD operation for an entity.Im using the context as private member accessible for all methods in the class.
public class CustomerService
{
private CeoPolandEntities context;
public CustomerService()
{
context = new CeoPolandEntities();
}
public bool IsCustomerValid(string userName,string password)
{
Customer customer;
customer = context.CustomerSet.FirstOrDefault(c => c.UserName == userName
&& c.Password == password);
return customer == null ? false : true;
}
public bool IsUserNameValid(string userName)
{
Customer customer;
customer = context.CustomerSet.FirstOrDefault(c => c.UserName == userName);
return customer == null ? true : false;
}
}
Is this a proper using of context ?? Is it thread safe and concurency safe??
Its a ASP.NET app.
Upvotes: 1
Views: 409
Reputation: 126547
Contexts aren't thread-safe.
Your current code is fine if:
Upvotes: 1
Reputation: 36027
As long as u have different instances of CustomerService to handle the different requests, u don't need to concern about that. If you happen to have any threads u create yourself, avoid calling multiple methods in the same instance.
Upvotes: 1