Glue – the new mapping framework
I’ve spent this summer implementing a new mapping framework for the .Net plattform: Glue.
You’ll find examples and code here: http://glue.codeplex.com
Glue is a general purpose, bidirectional automatic mapping for the .Net platform, with strong verification and testing tools.
I’ve seen quite a lot of less than optimal handling of mapping issues in quite a few projects over the years. Again and again mapping seems to be just a task we have to do, and a bit too small for automating. It becomes clearer and clearer to me that mapping is both an important task in many projects, and it is always a repetitive and boring task. In addition far to often subtle annoying bugs tend to sneak into mapping code. This motivated me to create Glue. And this is what I need from a mapping framework:
a) a way to automate mapping, mostly because it is boring, and that makes it error prone,
b) a way to automatically test the mapping, I’ve found that manual written test code for mapping is seldom done in a good way,
c) a way to prevent future changes making my mappings obsolete. When people make changes, they rarely focus on mapping (and honestly they should not either). They should be told when they have to update the mapping.
Now, you could argue that there is already a mapping framework available on the .Net plattform. And when I started this work, I actually started with that framework, thinking I could just make a few extensions to fulfil my needs. I actually spent some time in the source code to try to implement it, but sadly I realized that our needs differed too much. So, I created Glue, and these where the driving forces:
General purpose
Glue is a general purpose mapper. We realize that in the real world there are a lot of different solutions, and not all of them follow “the one true pattern”. In fact, mapping is often used to map to and from subsystems that are far from well designed. Subsystems we try to hide in a layer because we do not want it to leak into the other layers. Thus, we believe a mapper must support quite a few different scenarios. The goal is to promote good coding practices, but not to ignore the fact that there is a lot of legacy code out there that forces us to work a bit differently at times.
Bidirectional
I would say that in many mapping scenarios we need to map in both directions. First we get data from an object in a layer, and map it to an object in the layer above. When that layer is done with manipulating that object, we often want to map it back to down to the layer where it all came from. I have noticed not all mapping frameworks see it this way, and this was one of the reasons why I started working on Glue instead of trying to extend existing frameworks.
Strong verification and testing tools
I want to be absolutely certain that my mapping works. I also want to make sure that it is very hard to break it later. Manually writing tests for mapping is even more tedious than writing manual mapping. Glue automates this. Future changes has a sad reputation of breaking mapping code. Glue helps you detect this. Tools for helping the mapping is very important to me. And more tools will be available in future releases.
Simplicity
Mapping should be simple. Glue tries to simplify both the mapping process, and the verification and testing. You should not have to state the obvious, and Glue support relating properties automatically based on names.
Explicitness
Although Glue enables you to automate much of the mapping process, it also gives you the opportunity to be explicit about the mapping. So if you want to describe every relation in detail, you can. When it comes to understandable code this can be a good thing. Taking difficult to understand implicit mappings, and stating them explicitly can sometimes make things much easier to understand.
Current version and the future
The current version is 0.2.0 Alpha. It is still in Alpha because if we find good ways to improve the API, we do not want to lock ourselves to it just yet, before we get more feedback. I’m guessing the next release will be Beta.
I am currently using Glue on the project I am working on, and in about a month it will reach production. This somewhat guarantees that it will continue to evolve as our needs expand, and that we will find bugs sooner, and they will be fixed sooner.
Looking into the future we have some exciting ideas on tools to help with the mapping, and we are also working hard to make Glue as easy as possible to use, so expect simplifications. In addition we want Glue to serve a broad set of needs, so feedback is highly appreciated and if you explain your special needs, we might just implement it.
You’ll find examples and code here: http://glue.codeplex.com
- Tore Vestues


Hi Tore,
How is this different from the Automapper from Jimmy Bogard? Yes I am lazy, I will take a look at it later anyway, just curious.
-Mark
August 10th, 2009 at 13:14 (593)@Mark, thanks for the question, it is a very important one.
My intension is to make Glue more general purpose, and make it support more mapping scenarios than Automapper. In particular, it supports bidirectional mapping: you define the mapping once, and can use it to map both directions.
In this blogpost (http://bit.ly/14WmPF), Bogard writes :
“Some of the requests I’ve inferred include a lot of mapping from ViewModels back to Domain models. Personally, this seems wacky to me, unless you’re in some sort of ActiveRecord/CRUD scenario. In those cases, I’d rather expose my model directly to my views.”
This assumes:
1) that you only do mapping to and from a gui-layer. The way I see it, is that mapping can be done between any two layers or tiers. Glue supports this through being more generic.
2) that you only model your solutions the way Bogard thinks you should. I agree to much of what Bogard thinks about gui architecture, but living in the real world I often encounter existing systems where this is not the case. Glue supports other scenarios as well.
In addition I want Glue to be more focused on verification and testing. This is an important issue for me, in order to make mapping less fragile.
- Tore
August 10th, 2009 at 13:31 (605)Hi Tore,
Funny, I actually introduced AutoMapper to a solution right before I saw your post.
What scenarios related to verification and testing does your framework solve that AM does not?
August 10th, 2009 at 19:31 (855)@Øyvind,
At the moment we support two things:
First, as Automapper, Glue supports a way to validate your configuration. Meaning you can check if all the properties on one or both of the types have been related (or ignored). See: http://glue.codeplex.com/Wiki/View.aspx?title=Verification%20of%20relations
Second, and this is not supported by Automapper as fas as I can see, Glue supports to actual test the mapping. Meaning it sends random values through the converters (if any) and sets the values on an actual object to validate that the value is set, and that no exception is thrown in the process: http://glue.codeplex.com/Wiki/View.aspx?title=Testing%20the%20mapping
The next release will also contain some debug/analyzing tool to make it simpler to see what is actually being mapped.
-Tore
August 10th, 2009 at 22:05 (962)Hello,
I posted a few questions about Glue in Codeplex:
http://glue.codeplex.com/Thread/View.aspx?ThreadId=69383
I am not sure if it would be better to post here but in Codeplex is better so I can post it with code.
Thank You,
September 18th, 2009 at 15:51 (702)Miguel
@Miguel,
I’ve answered your questions on the codeplex-site.
-Tore
September 18th, 2009 at 21:07 (921)Hi – running into issues with Glue and mapping nested collections and lists – I cannot seem to get it working – is there an email address I can contact you on?
November 1st, 2011 at 14:23 (641)