This repository has been archived by the owner. It is now read-only.

Adding support for a new container

hmemcpy edited this page Jun 6, 2012 · 17 revisions

Note: this is a preliminary bunch of notes, the instructions below might change.

Step 0

Create a new branch with the name of the container you'd like to add. I highly recommend using git-flow for a successful branching model.

Step 1 - Creating and preparing a new project

  1. Create a new Class Library project, targeting .NET 4, in the AgentMulder\src\ directory, with the following name: AgentMulder.Containers.DIContainerName, e.g. AgentMulder.Containers.StructureMap.
  2. Once the project is created, Unload the project from the solution, then Edit the .csproj file.
  3. Add the following:
    <ReSharperSdkTargets Condition=" '$(ReSharperSdkTargets)' == '' ">$(MSBuildExtensionsPath)\JetBrains\ReSharper.SDK\v6.1</ReSharperSdkTargets>
  <Import Project="$(ReSharperSdkTargets)\Plugin.Targets" />

Right above the line:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  1. Reload the project into the solution, and place it into the solution folder Containers.

  2. Set the build output path to ..\..\output\Debug\Containers\ and ..\..\output\Release\Containers\ for Debug and Release configurations, respectively.

Step 2 - Tests structure

Most tests in the Agent Mulder plugin are integration tests, because they require the entire ReSharper ecosystem, from solution structure to pattern searching mechanisms. ReSharper SDK provides base test fixtures that are capable of creating a test solution and loading code files into it. There are two projects related to tests: AgentMulder.ReSharper.Tests, which contains the test fixtures, and TestApplication, essentially a console application which contains types (interfaces and concrete) to load into the containers, as well as small classes that have a single container call with a specific syntax.

The TestApplication project and all the files referenced in it are located in a special subdirectory, src\Test\Data, because ReSharper's base test fixtures are using this directory as the base directory to load user classes. Refer to Unit Testing Agent Mulder plugin for more information.

  1. In AgentMulder.ReSharper.Tests create a new directory named after the container, e.g. StructureMap.
  2. Add a reference to the container (via NuGet or manually) - this is optional.
  3. Create a new attribute called Test[ContainerName]Attribute, e.g. TestStructureMapAttribute, deriving from TestReferencesAttribute, and supply the location of the container assembly:
using StructureMap;

public class TestStructureMapAttribute : TestReferencesAttribute
  public override string[] GetReferences()
    return new[] { typeof(IContainer).Assembly.Location }; 
  1. Save this class under Helpers folder, i.e. StructureMap\Helpers.

In the TestApplication project create a folder with the name of the container, e.g. StructureMap, and add a reference to the container assembly (via NuGet).

You should create a class exercising a single construct of the container, and create a test case calling that class. See examples in the implementations of existing containers in the Agent Mulder source code.

Step 3 - Pattern matching

You should first create the pattern to match a specific registration using ReSharper's Search with Pattern dialog. Once the pattern has been found, you need to translate it to code. Refer to ReSharper's Structural Search for more details on the API.

Step 4 - Putting it all together

Continue reading Implementing Container Support.