Dependecy injection and unit testing - static helper methods or private instance methods

From single testing and from the point of view of injection of injections, what is the usual accepted norm when it comes to auxiliary methods?

Here is my sample situation:

public class GoodiesController : Controller
{
   private IMyContext _context;

   public GoodiesController(IMyContext context)
   {
      _context = context
   }

   public async Task<IAction> GetThoseGoodies()
   { 
       if(YouLikeThemThisWay(Request.Path))
        {
           var result = await _context.GoGetThemThisWay()
        } else { }
    }

My question is: am I better off YouLikeThemThisWay(string path)being a static helper in some class or as a private instance method? Assuming I might have a couple of these YouLikeThemThisWay?

+4
source share
1 answer

It really depends on what your method does YouLikeThemThisWay(string path). My rules for using a static method or as follows:

  • ? , static.
  • ? , static.
  • , ( IE BCL)? , !
  • - - ? , !
  • ? , !
  • - IO, , ? , .

, , , OK, . , , , IO IPC, .

, . , .

. , . , .

EDIT: , , , , - .

+4

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


All Articles