Conventions are created by implementing various interfaces that are provided by Fluent NHibernate. Which interfaces you choose depends on what mappings you want to alter.
The conventions are actually built using conventions themselves -- how very meta of us -- which has the side-effect of you having a nice gradient of granularity. If there isn't a specific interface available for what you need, you can just go to the "level" above and implement it yourself. There's only one real convention (which is IEntireMappingsConvention), everything else is just an implementation of that interface (or other interfaces that are implementations of it).
I'll cover all the available interfaces as of writing, and what their purpose is below.
| Convention | Parameter | Description |
|---|---|---|
| IEntireMappingsConvention | IEnumerable<IClassMap> | Applied to an enumeration of all the class mappings that Fluent NHibernate is going to inject into NHibernate. This is the highest-level convention you can implement, and should really only be used to provide more granular conventions. |
| IClassConvention | IClassMap | Applied individually to each class mapping. Implement this interface to customise things like table names, default-insert/update parameters, caching, locking etc... Anything that would be set just on the class. |
| IMappingPartConvention | IMappingPart | Applied individually to each IMappingPart in a classlike parent (ClassMap, join's, components etc...). Every sub-mapping is a mapping part, so this convention will be applied to everything inside the mappings. This interface is probably too general to be of much use, unless you're wanting to provide new conventions. If we're missing a convention, this is likely the one you'll need to implement to work around it. |
| IIdConvention | IIdentityPart | Applied individually to each Identity in your mappings. Implement this interface if you need to customise only identities. |
| IPropertyConvention | IProperty | Applied individually to each Property in your mappings. Implement this interface if you need to customise only properties, good for customising column names and access strategies. |
| IVersionConvention | IVersion | Applied individually to each Version in your mappings. Implement this interface if you need to customise only versions. |
| IJoinConvention | IJoin | Applied individually to each Join in your mappings. Implement this interface if you need to customise only join mappings. It's important to know that joins can contain other IMappingParts, so any implementors of IMappingPartConvention will also get called for any children of a join. |
| IComponentConvention | IComponent | Applied individually to each Component in your mappings. Implement this interface if you need to customise only component mappings. It's important to know that components can contain other IMappingParts, so any implementors of IMappingPartConvention will also get called for any children of a component. |
| IDynamicComponentConvention | IDynamicComponent | Applied individually to each Dynamic Component in your mappings. Implement this interface if you need to customise only dynamic component mappings. It's important to know that dynamic components can contain other IMappingParts, so any implementors of IMappingPartConvention will also get called for any children of a dynamic component. |
| IRelationshipConvention | IRelationship | Applied individually to each relationship in your mappings, this is a catch-all for one-to-many, many-to-many, many-to-one and one-to-one mappings. Implement this interface if you need to customise all relationships in your mappings, generally you need something more fine-grained than this, but it's here incase you need it (and we use it to implement the other relationship conventions). |
| IHasOneConvention | IOneToOnePart | Applied individually to each one-to-one relationship in your mappings. Implement this interface if you need to customise all HasOne relationships. |
| IHasManyConvention | IOneToManyPart | Applied individually to each one-to-many relationship in your mappings. Implement this interface if you need to customise all HasMany relationships. |
| IHasManyToManyConvention | IManyToManyPart | Applied individually to each many-to-many relationship in your mappings. Implement this interface if you need to customise all HasManyToMany relationships. |
| IReferenceConvention | IManyToOnePart | Applied individually to each many-to-one relationship in your mappings. Implement this interface if you need to customise all Reference relationships. |
| IUserTypeConvention | IProperty | Simple IUserType convention, implement this to act on properties with IUserTypes. There's a UserTypeConvention base class that is easier to use than this interface. |
Here is a basic hierarchy diagram of how the conventions are laid out, each convention to the right of another is an implementor of that interface. IMappingParts are recursive, so each one of them calls all the children under the class mapping part convention.
+- IIdConvention
|
+- IPropertyConvention --------- IUserTypeConvention
|
+- IVersionConvention
|
+- IJoinConvention ------------- IMappingPartConvention*
|
IEntireMappingsConvention - IClassConvention - IMappingPartConvention -+- IComponentConvention -------- IMappingPartConvention*
|
+- IDynamicComponentConvention - IMappingPartConvention*
|
| +--- IHasOneConvention
| |
| +--- IHasManyConvention
+- IRelationshipConvention -|
+--- IHasManyToManyConvention
|
+--- IReferenceConvention
* Recursive - These mapping part conventions are applied recusively, inheriting the behavior from the mapping part convention under the class convention