I’ve made availble a svn repository with the source code of the channel library for Spring.Net and my work on a Cuyahoga module for events. The last one is still pretty much a work in progress. I think I’ll be able to work on it some more later this year. There’s a lot on my todo list.
Readers have reported that the latest version of Fluent NHibernate breaks the approach which I illustrated on this blog, I’ll look into that later today. I’ll also be patching the channel library with a bug fix which someone on the Spring.Net forum was kind enough to provide. Had hoped to do that yesterday but the machine on which I was working did not have NUnit installed and Sourceforge was down. So stay tuned, this blog will get some more action in August.
Repository is located at:
Edit: Moved code to github @ https://github.com/BennyM/SpringWCFChannelManager
This took me some time to figure out since documentation for Fluent NHibernate is still a little scarce. Let’s say we have an entity “ActivityType” which has an icon and a name, but the name is stored for each language so we have a one to many relationship. This relationship is not only modelled in the entity “ActivityType” but also in several others. The translation is modelled in the “LocalizedEntity” class. As illustrated in the class diagram below:
The DB is illustrated in the next diagram, to make it easy the tables have a different name compared to the entity diagram :p.
The mapping for the “Language” entity is pretty straightforward. The mapping for the “ActivityType” and its localizations was a bigger challenge since I got lost in all the delegates after the Component method.
public class LanuageMapping
Id(x => x.Id);
Map(x => x.Name);
public class ActivityTypeMapping
Id(activityType => activityType.Id);
Map(activityType => activityType.IconName);
HasMany<LocalizedEntity>(activityType => activityType.Descriptions)
description.References<Language>(desc => desc.Language)
description.Map(desc => desc.Localization)
In order to load the mappings you’ve written using Fluent NHibernate you need to call the extension method “AddMappingsFromAssembly” on the configuration. The “LocalSessionFactoryObject” defined in Spring.Net supports out of the box the loading of .hbm files from an assembly or a location in the file system. Luckily this class can be extended with ease. The code below is all you need to use Fluent NHibernate with Spring.Net, any suggestions for a better name are welcome.
public class FluentNhibernateLocalSessionFactoryObject
/// Sets the assemblies to load that contain fluent nhibernate mappings.
/// <value>The mapping assemblies.</value>
public string FluentNhibernateMappingAssemblies
protected override void PostProcessConfiguration(Configuration config)
if(FluentNhibernateMappingAssemblies != null)
foreach(string assemblyName in FluentNhibernateMappingAssemblies)
Update 29 June: please check the comments since a new version brought some changes to this blog post.