When is it best to use static functions in ASP.NET?

后端 未结 3 2136
走了就别回头了
走了就别回头了 2021-02-10 01:34

I have been wondering, when to use static functions, and when not to in ASP.NET?

What are the advantages and disadvantages in using them, in various aspects like perform

3条回答
  •  爱一瞬间的悲伤
    2021-02-10 02:07

    The only major disadvantage to a static method is that it's almost entirely non-unit testable. Users of the method have to bind to the concrete method and cannot bind to an abstraction, thus making faking or mocking difficult if not impossible.

    This may or may not be an issue, depending on the code, however.

    The other thing you want to watch out for is that static data is universal across all requests to the server.

提交回复
热议问题