📜 ⬆️ ⬇️

Resharper and IoC containers: now familiar! or Agent Mulder plugin

Good time,

As you know, Resharper solves a lot of problems with working with the code, but still not everything.

One of this, not very resolved, problem is navigating through the classes registered in IoC.
')


Consider a simple example (using the Unity IoC container from Microsoft).
  IUnityContainer container = new UnityContainer(); container.RegisterType<IMovieRepository, InMemoryMovieRepository>(); container.RegisterType<IMovieFinder, MovieFinder>(); 
IUnityContainer container = new UnityContainer(); container.RegisterType<IMovieRepository, InMemoryMovieRepository>(); container.RegisterType<IMovieFinder, MovieFinder>();


In this example, Resharper "does not know" where the MovieFinder constructor is used and issues a message (at the Find Usages command) "Usages of 'MovieFinder (...)' was not found" .
  public class MovieFinder: IMovieFinder { readonly IMovieRepository repository; public MovieFinder(IMovieRepository repository) { this.repository = repository; } ... } 
public class MovieFinder: IMovieFinder { readonly IMovieRepository repository; public MovieFinder(IMovieRepository repository) { this.repository = repository; } ... }



The situation is even worse if the registration does not use the class name. In this case, the class will be shown by Resharper as not used.

But, in order to “introduce” Resharper and IoC containers, a solution was found.
Apparently using the famous phrase " let everything be, but something is missing, " the developers of Resharper added the ability to write plugins.
This is what Igal Tabachnik used .

The Agent Mulder plugin analyzes containers and provides convenient navigation between classes and their registration.

So, the plugin provides 3 main features:

1. Marks classes registered in the container with a special icon:
image

2. Provide navigation from class definition to place of registration.

3. And back, navigating from registering to defining classes.
image

Everything works quickly and accurately, but, unfortunately, sometimes (VS2010 + Reshaper 6.1) navigation does not work as perfectly as we would like. I hope these shortcomings will be quickly eliminated, because the thing is useful in the economy.

Everything around the plugin itself (website, documentation, installation) is done well and works without problems.

Plugin site: http://hmemcpy.github.com/AgentMulder/ contains a simple but clear description. There is a video that explains even easier.

The plugin has already hit the Resharper site . I counted 17 plug-ins there, 4 of them are agents.

A list of supported containers can be found here https://raw.github.com/hmemcpy/AgentMulder/master/WhatsNew.txt .
By the way, for good, you need to write a plugin system for this plugin to add your IoC containers :).

Detailed video " Dmitry Nesteruk. ReSharper: Architecture and Extensions " from mezastel can serve as an introduction to the world of resharper plug-ins.

Igor

Source: https://habr.com/ru/post/145958/


All Articles