Introducing IoCTesting

Reading time ~1 minute

Last week I've worked in a tiny library to test if you have configured all the dependencies in your code in the IoC container. I borrowed the idea from this post from Juan María Hernández. The idea is simple, but it can save you some time of debugging.

Install the library is quite straightforward: just install the NuGet package you need depending on the container you are using:

install-package IoCTesting.StructureMap
install-package IoCTesting.Unity

To be able to use the library you need to have a method that returns the container. If you use StructureMap, you must have something like this:

public IContainer CreateContainer()
    return new Container(x =>

The method could be static. The library will scan the assembly looking for this method and will call it to have the container initialized. After that, it will scan your assembly looking for classes that have a constructor with abstract classes or interfaces as parameters, and it will query the container to see if there's some registration for that type.

So, for example you can have a call like this:

var structureMapTesting = new IoCTestingStructureMap();
var errors = structureMapTesting.CheckDependencies(RegisteringAssemblyPath, RegisteringMethodName, TestingAssemblyPath, NamespaceToScan);

As you can see the library takes four parameters:

  • The full path of the assembly where the registration is performed.
  • The qualified name of the class that performs the registration.
  • The assembly you want to scan
  • The root namespace you want to scan. Types that its namespace doesn't start with it won't be scanned.

And returns an IEnumerable<string> with all the classes or interfaces not registered. Only supports constructor injection, not property injection.

And that's all. I hope it can be useful for you. If you have some issue or comment, please do it in the project page.



Using different configuration per stage

In the [previous article](./deploy-serverless-app/) we saw how to create a basic deployment pipeline for a serverless application. In thi...… Continue reading

Deploying a serverless application

Published on April 19, 2018

Dynamic secrets with Vault

Published on December 16, 2017