Chapter 1. Using the Spring.NET Visual Studio Extension

The Spring Extension provides IntelliSense assistance in authoring Spring XML configuration files in Visual Studio .NET 2010. It provides the following features:

The extension is open-source (Apache 2.0 License) and hosted on GitHub here. Contributors are more than welcome to help improve the feature set of the extension. Note that an alternative, fully code base configuration option is also now available for the Spring.NET container. More information can be found on the Spring.NET home page.

There is a screencast showing the extension in action. Check it out!.

1.1. Installation

To install the extension double click on the Spring.VisualStudio-1.0.0.msi file after unzipping the distribution. The installation will not prompt you for any information. Once the install screen is gone, start up VS.NET 2010. In VS.NET if you select "Help->About Visual Studio you will see an entry in the installed products window named "Spring.NET Visual Studio Extension 1.0.0". You will also be able to see it listed under the Tools->Extension Manager Window as shown below.

To do a tour of the features, we will use the MovieFinder example that ships with the distribution of Spring.NET. The C# code listings for the MovieFinder application can be found in the examples/Spring/Spring.Examples.MovieFinder directory off the top level directory of the Spring.NET distribution.

To prepare the example for use exploring the VS.NET extension, go to App.config and remove the following section of Spring XML configuration.

      <object id="MyMovieLister" 
              type="Spring.IocQuickStart.MovieFinder.MovieLister, Spring.IocQuickStart.MovieFinder">
        <property name="MovieFinder" ref="AnotherMovieFinder"/>
      </object>
     
      
      <!-- An IMovieFinder implementation that uses harcoded values as it's movie source... -->
      <object id="MyMovieFinder" 
              type="Spring.IocQuickStart.MovieFinder.SimpleMovieFinder, Spring.IocQuickStart.MovieFinder"/>
      
      <!-- An IMovieFinder implementation that uses a text file as it's movie source...     -->
      <object id="AnotherMovieFinder" 
              type="Spring.IocQuickStart.MovieFinder.ColonDelimitedMovieFinder, Spring.IocQuickStart.MovieFinder">
        <constructor-arg index="0" value="movies.txt"/>
      </object>

We will recreate the object definitions using the VS.NET tooling.

1.2. Type Completion

Using the type completion feature you will be able to easily navigate to the type that you want to include in a Spring XML object definition.

Open up App.config and go to the section of the file where you just deleted the XML object definitions described in the previous section. Let us now recreate the XML object definition for 'AnotherMovieFinder' (Note that 'MyMovieFinder' was not really used in the out of the box configuration of the example). Start typing

<object id="AnotherMovieFinder" type="

At this point you will see a drop down list of primitive types offered up for code completion since without additional information provided by you, that is the only suggestions the extension can provide for a type.

You should start typing out the namespace where AnotherMovieFinder lives, in this case typing Spring.Io will get you going and you will have a screen as shown below.

As you type out Spring.Io you will see a drop down box for the various namespaces you can get come content assist with. In this case since the first part of our namespace is 'Spring' we see some namespaces that are part of the Spring framework itself. If you use the arrow keys to select one the namespace names (or type out Spring.IocQuickStart.MovieFinder) you will end up with the following

We have reached the class we were interested in and can also see the documentation of that class to help us ensure this is in fact the correct class we want to configure. The documentation in a Quick Info tooltip box. This is shown better in the following image.

Selecting ColonDelimitedMovieFinder and closing the XML with a "> will leave you with the following - note that the assembly name has been entered in for you automatically.

We are now ready to configure the ColonDelilmitedMovieFinder with constructor and/or property element using the VS.NET extension.

1.3. Property name completion

If you start typing out the XML configuration for the property of the existing XML object definition for ColonDelimtedMovieFinder as shown the previous step - once you have type the 'quote" to enter the name of the property, then hit CTRL-SPACE to get completion of the property names for that object. In this case, the only property is MovieFile as shown below:

You can then use the cursor key to select the property. You also can see a Quick Info tooltip box showing the documentation for that property. The completed XML object definition looks like this

1.4. Constructor argument name completion

Starting from the object definition that has only the type name defined, we can also use constructor arguments to configure the ColonDelimtedMovieFinder. Start typing out

<constructor-arg name="

and then hit CTRL-SPACE. You will see the name of the constructor argument, in this case called file, as shown below.

Select the file name with the cursor and then fill in the value 'movies.txt'. You will end up with the configuration shown below

1.5. Snippits integration

Code Snippets are a feature of VS.NET that provide structure to help you fill in common code/configuration tasks In the previous sections we were typing in by hand the <object id=" part of the object definition. While XML IntelliSense offers help in creating an object definition, the Code Snippet approach provides added convenience, in particular when using to create a definition of an often used object such as VariablePlaceholderConfigurer. If you open up the Code Snippips manager (CTRL+K+B) you will see the list of installed snippits as shown below

We will use the object Code Snippet to create an definition for the MovieLister object. Type CTRL+K+X in the Spring XML file and you will be presented with a menu of options to select from, these are categorized by the area of Spring functionality (Aop, Core, Web).

Selecting Core and then Object will create the shell of the XML fragment to fill in as shown below

You enter "MyMovieFinder" and then hit TAB you will be taken to the type=" " placeholder where you can use the type completion features of the Spring extension to enter the type Spring.IocQuickStart.MovieFinder.MovieLister, Spring.IocQuickStart.MovieFinder. This is shown below.

The property name "MovieFinder" can also be completed for you as described in a previous section. However the ref="AnotherMovieFinder" is not completed for you and you will need to match the reference name to the name of the object without any IDE assistance. The completed XML that will run the MovieFinder application is shown below.

Now you are ready to run the example application!