I’m adding pluggable type conventions to our NHibernate mapping Fluent Interface today:
public interface ITypeConvention
{
bool CanHandle(Type type);
void AlterMap(IProperty property);
}
public interface IProperty
{
void AddAlteration(Action action);
void UseThisType() where T : IUserType;
void SetAttributeOnPropertyElement(string name, string key);
}
Anyway, one of the design ideas we can steal from Ruby on Rails is the convention over configuration philosophy. Part of the efficiency gain I think we make by moving from hbm.xml configuration to the FI is taking advantage of conventions tied to object types. We've made the FI smart enough to respond to some class and property types. The code above is going to make these conventions pluggable. Today, I'm adding a custom IUserType for our Value Objects. I'm creating the hook above to plug in a rule that says that any property subclassing type ValueObject will be mapped using this new IUserType.
Here's some examples of conventions:
-
You're trying to create a mapping for a class that subclasses DomainEntity? Why don't I just automatically set up the identifier node for you pointing to the Id property. I'll add property mappings for all those common audit trail columns too.
-
You got an enumeration type? I'll just stick in an EntityStringType for you.
More results, less code, and fewer lines of XmHell.