Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • But what about cases where a class is Resolved by -but not Registered in- the IoC container and one of its dependencies is missing? Automated tests would only pick that up if you test the Resolution of all types in your application, or, if you did some static analysis to find out which types could be subject to Resolution... which starts smelling like the halting problem. Commented May 30, 2016 at 18:37
  • @MetaFight: I know that it won't work in all cases, maybe I should have said that clearer in my answer. But then...SimpleInjector's Verify() does "iterate over all registrations and resolve an instance for each registration" (quote from the docs), so if any of those types' dependencies are missing, my approach would catch that. Can you give an example where you think my approach wouldn't work? Commented May 30, 2016 at 19:01
  • Your approach only considers registered types. It won't cover cases where the dev uses the IoC container to resolve classes completely disconnected from the registered class graph. Eg, IoC.Register<A>(); IoC.Register<B>(); var z = IoC.Resolve<Z>(). Z hasn't been registered therefore your test doesn't check if it resolves correctly. So, if Z has dependency Y, which also isn't registered, we only see this at runtime. Commented May 30, 2016 at 20:48
  • I've never seen someone do that...but then again, I'm not that experienced with IoC. So for my use cases, when I know that I'll never try to resolve something I didn't register before, my approach does the job. Commented May 30, 2016 at 21:06