ASP.NET MVC guidelines for static classes for database access

asp.net-mvc c# entity-framework

Accepted Answer

ZZZ_tmp
8
2/12/2016 5:18:20 PM

Popular Answer

I had intended to add a comment to ChrisPratt's response, but it turned out to be too lengthy, so let me make a separate response instead.

In essence, this is not a life-or-death decision. Yes, static methods for database access are less versatile than classes. But They're not awful. in general. A a target to strive for is a single DbContext per request. It is not absolutely necessary. It is equivalent to dependency injection, which results in more freedom but also more complex code.

I'm confident you can find the answer to your query by carefully examining the following three questions and their responses:

EDIT: Chris provided some insightful feedback on my response, and I've modified it slightly in response.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow