Agent Mulder – supporting IoC in ReSharper

The almost pervasive use of IoC containers in modern-day enterprise apps presents a special challenge to ReSharper. After all, how can ReSharper possibly know that a type, which for all intents and purposes appears to be unused, is actually configured to be instantiated implicitly by using a dependency injection mechanism?

Some might say that this is impossible, since the wide variety of IoC containers coupled with various distinct initialization options make the detection of component initialization a real challenge. This challenge was met, however, by Igal Tabachnik (@hmemcpy), the creator of the Agent Mulder plugin.

At the time of writing, Agent Mulder supports the following containers:

  • Castle Windsor

  • NInject

  • Unity

  • Autofac

  • StructureMap

  • Catel IoC

Depending on the container in question, Agent Mulder supports two types of component registration:

  • Manual registration involves registering a single component type in the container. This is typically done by providing the component’s type, so for example with Unity one might invoke RegisterType<Foo>() or RegisterType(typeof(Foo),...) to add the component to the container.

  • Convention-based registration allows bulk registration of components in the container via a particular method. For example, Autofac’s InNamespaceOf<T>() method allows the user to register all types that can be found inside the namespace inhabited by type T.

While it is technically infeasible for Agent Mulder to support every variety of configuration in every container, it does manage to cover a very large percentage of configuration options in the aforementioned containers, as documented in its Wiki pages. But, apart from analyzing container registrations, what does the plugin actually do?

Ultimately, Agent Mulder does three things:

  • The main goal of Agent Mulder is to suppress unused ispections when a container-registered component does not appear to be instantiated.

  • In addition, Mulder also uses a gutter mark to indicate a container-registered component. One can click this gutter mark to navigate to the exact line where this component is registered:

  • Finally, one can also navigate to registered component right from the statement that performs the registration:

Mulder is an open-source plugin hosted on GitHub. It appears to have an active user base, so if you are interested in, say, a container it doesn’t support, feel free to open a request or implement it yourself and send a pull request. Meanwhile, have fun with IoC and stay tuned for more plugin reviews!

image description