Tuesday, 28 February 2012

Spring woes

This blog: http://onlytalkingsense.wordpress.com/2006/06/06/springnet-and-generics/ ... just saved me a tonne of pain. Although admittedly this was after suffering about 2 hours of pain at the hands of Spring.Net completely failing to work all of a sudden.

I'd just re-factored some caching code out of an application-specific project and into a general support library. The caching system is set up in Spring.Net and uses generics syntax to define a cache (which is HashSet based) of an application entity object. This was fine before I re-factored because both the cache and the entity object were in the same assembly. However, after the re-factoring, Spring was completely unable to initialise the caches and saying that it couldn't find the type.

The blog explains that if you are using the generics syntax to define an object which consists of objects that are from a different assembly, then it is not sufficient to use the long-hand qualification syntax. You need instead to create a typeAlias entry for each of those objects from outside of the generic's assembly.

So I was expecting the following to work:

<object id="ThisDoesntWork"
type="Asura.Storage.Caching.Cache&lt;PPT.Entities.Contact, PPT.Entities>, Asura.Storage">

But instead I had to add this to the config sections:

<section name="typeAliases" type="Spring.Context.Support.TypeAliasesSectionHandler, Spring.Core"/>

And then this to the spring section:

<alias name="Contact" type="PPT.Entities.Contact, PPT.Entities" />

And then the object itself looks like this:

<object id="ThisDoesWork" type="Asura.Storage.Caching.Cache&lt;Contact>, Asura.Storage">

Anyway, see http://onlytalkingsense.wordpress.com/2006/06/06/springnet-and-generics/ for the full article.

No comments:

Post a comment