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!

Comments below can no longer be edited.

8 Responses to Agent Mulder – supporting IoC in ReSharper

  1. Avatar

    MEF says:

    January 24, 2013

    MEF would be great 🙂

  2. Avatar

    Adam says:

    January 25, 2013

    Am I missing something or does it currently require users to download the sources and compile them (which in turn requires installing resharper’s sdk…)?

  3. Avatar

    Dmitri Nesteruk says:

    January 25, 2013

    @MEF: support for many different frameworks would indeed be great. However, Igal can only cover so much. That said, feel free to help him!

    @Adam: you can find a link to the latest MSI installer on the following page:

  4. Avatar

    Igal Tabachnik says:

    January 26, 2013

    Thank you very much for the post! 🙂

    At this point, the Agent Mulder plugin utilizes ReSharper’s “Search and Replace” (SSR) mechanism to look for registration patterns in the code. Unfortunately, it has some limitations, such as looking for particular attribute types, therefore currently MEF is not supported. I am thinking about ways to solving it, so at the very least I can say that MEF support is coming, but I can’t say when.
    If you want to know more about how Agent Mulder works, I have some information on the wiki:

    Ever since Github decided to remove the Downloads feature, the link is, unfortunately, not very visible. You can download it from the site here:

  5. Avatar

    Peter Mounce says:

    August 14, 2013

    Is it possible to apply plugins to the new command-line inspection-runner that ships in R# 8, and has been available within TeamCity for a while?

  6. Avatar

    Dmitry Matveev says:

    August 14, 2013

    Currently, it is impossible. However, we plan to implement that soon, in one of the coming releases of ReSharper Command Line Tools. Please stay in touch.

  7. Avatar

    Jonathan says:

    February 23, 2017

    What would be required to pull this into ReSharper 2016.3?

  8. Avatar

    Per Atle Holvik says:

    March 9, 2017

    I have the same question as @Jonathan.

    As of Aug 9, 2016, the project is no longer maintained. Might JetBrains can take over maintenance of it?

Discover more