Static method at the data access level

I used many static methods in the Data Access Layer (DAL), for example:

public static DataTable GetClientNames() { return CommonDAL.GetDataTable("...."); } 

But I found out that some developers don't like the idea of ​​a static method inside DAL. I just need for some reason to use or not use static methods inside DAL.

thanks

Tony

+4
source share
3 answers

From the point of view of purists, this violates all kinds of best practices (for example, dependence on implementation, tight coupling, opaque dependencies, etc.). I would say this myself, but lately I have been leaning towards simpler solutions, not diving too much into the enterpriseizey functions and keywords. Therefore, if it’s good with you, write such code, if this architecture allows you to quickly develop and test and, most importantly, solve your business problem - it’s just fine.

+3
source

If I had to choose one reason not to use static methods, it would be that it limited your ability to write unit tests against your code. For example, creating mocks for your DAL will be more complicated because there is no actual interface for the code, but just a bunch of static methods. This further limits you if / when you decide to accept frameworks that require interfaces to support things like IoC, dependency injection, etc.

+1
source

That Unit of Work is just static, isn't it?

0
source

Source: https://habr.com/ru/post/1347448/


All Articles