Glue 0.9 “Magic” Released

My feelings on magic
(Feel free to skip this section if you couldn’t care less about my thoughts on automagic)
I am not the biggest fan of automagical behavior. For that reason, up until now, Glue has not automatically created new objects when you map. You have to instantiate the object to map to (and all nested objects within that object). The reason for this is that I want the developer to explicitly decide when it comes to how objects are to be created. Personally I like to be in control, so that problems do not arise at inconvenient times (like at runtime in a production environment).
In addition, I come from the OO school. I believe that objects should be, yes, objects, and not just data containers (a typical data container is a class containing only properties, and little or no logic). I believe objects should be relevant, individual, and contain logic. This often means that constructing them is not something you let a framework do (unless it is a framework specialized for that kind of job). Because constructing them often means making decisions, like what dependencies these objects should have.
The “General purpose” mapping framework
One of the driving forces for creating Glue was to create a general purpose mapping framework. Meaning it should support different scenarios, not just the ones I liked the most. In addition, using Glue extensively myself, I have found that there are (quite a lot of) times when having Glue create objects for me are both convenient, and low risk.
Automagical and Strict mode
So, with version 0.9 of Glue, I introduce the “Automagical” mode where Glue tries to instantiate objects whenever necessary. In addition, the existing behavior (making you create all the objects) is now named “Strict” mode. Choosing between the modes is simply done by choosing the right overload of the Mapper.Map-method. Intellisense will guide you.
Examples can be found here
Download Glue 0.9 binaries here
- Tore Vestues


I think adding this is a right decision. I would think that most people use mappers when mapping from rich models to DTO’s and expose them across boundaries. Making rich objects automatically with a mapping framework may not be so smart, but mapping to DTO’s, it makes a lot of sense.
January 6th, 2011 at 9:51 (452)You could add the ability to restrict the magic by f.ex. providing a list where you define what types can be constructed ‘magically’ and you could even add a collection of factories so that still nothing gets done automatically but explicit by a factory, with a default factory that can create everything perhaps
-Mark
January 6th, 2011 at 15:39 (694)I’m new with Glue so excuse me if it is a dumb question.
It is possible to use glue to check if objects are synch with each other or one was changed after Map() ?
something like:
bool CompareRelated(LeftType leftObject, RightType rightObject)
September 29th, 2011 at 1:15 (093)Paul,
This is not possible at the moment. I have however been thinking about adding some functionality in that direction. If you want to describe your need in more detail feel free to add a feature request here: http://glue.codeplex.com/workitem/list/basic
-Tore Vestues
October 8th, 2011 at 6:56 (331)Is possible to acheive something like that with Glue?:
var mapping = new Mapping();
where LeftType is an Object Type that I know it has to be a similar structure than RightType. In other words, LeftType and RightType, must to be known types?
November 2nd, 2011 at 15:46 (699)José Miguel: I’ve tried to answer your question here: http://glue.codeplex.com/discussions/278049
November 2nd, 2011 at 21:19 (929)