I understand that Static members can cause concurrency issues in ASP.Net or any other .net based system where multiple users will access and use the same threads.
My question is whether it's safe to use Static Methods when I pass in context as a parameter. Example:
public class BL
{
public static List<DocumentType> GetAllActiveDocumentTypesForMyDeparment(int CurrentDepartment)
{
return Data.DAL.GetAllActiveDocumentTypesForMyDeparment(CurrentDepartment).Where(s => s.IsActive)
.OrderBy(s => s.DocumentTypeDisplayName).ToList();
}
}
Will the above cause concurrency issues? Take note that my DAL is also using a static Method.
I understand there are lots of articles about Static vs Instance and i've read alot of them, but I found the best way to really understand something is to write code and test it. Thanks
I understand that Static members can cause concurrency issues in ASP.Net or any other .net based system where multiple users will access and use the same threads.
Well only if it modifies shared state, or performs some sort of synchronization.
My question is whether it's safe to use Static Methods when I pass in context as a parameter.
Sure. It's not like other threads will see that parameter or have access to it. Of course, you have to be performing thread-safe work within the static method, but that's all.
I suggest you go back to whatever sources were suggesting that static members cause concurrency issues, and really try to understand when and why that's the case. It's definitely not a blanket rule you can apply without further consideration.
See more on this question at Stackoverflow