DISQUS

Emad Ibrahim: Mocking and Dependency Injection in ASP.NET MVC

  • Adrian Grigore · 6 months ago
    Excellent post! I've been looking for a way to DRY up my own code as well and your post led me on the right way.
  • Adrian Grigore · 6 months ago
    One more thing I only thought about once I was implementing your technique in my project: How do you test your StandardModule.Load bindings? I'm sure I'll forget adding one of those sooner or later.
  • eibrahim · 6 months ago
    Good question. I actually don't test it and I have forgotten to add a few
    items before but unfortunately, it is a runtime error. What I would rather
    do but I am too lazy to is have this information loaded from a configuration
    file instead, so if you forget to add something, you can just edit the
    config file without having to recompile/re-deploy.

    Ninject doesn't support config files which is ironically why I like it.

    A solution would be to create a test everytime you add an "injectable" class
    to test if it is getting loaded/injected properly or not. This should be a
    simple IsNotNull test. (I think).