As of version 2.1, NHibernate supports constructor injection for IUserTypes via IoC container (supplied through the ByteCodeProvider config setting).
However, when I try to get this working through Fluent NHibernate configuration (not auto mapping), when I build my configuration, I get an exception complaining that one of my objects (a custom ICompositeUserType, in this case) does not have an empty default constructor.
I traced this exception down to a call to Activator.CreateInstance() in FluentNHibernate.Mapping.PropertyPart.AddColumnsFromCompositeUserType(Type compositeUserType).
The whole point of NHibernate’s IoC support feature was to replace calls to Activator.CreateInstance with calls to the provided custom ByteCodeProvider.
So I guess my question is this: is it possible to get this working with Fluent NHibernate, or do I have to scrap my Fluent NH configuration and go back to NHibernate’s built-in programmatic configuration?
Links to blog posts about this feature:
UPDATE: it looks like the problem is with FluentNHibernate’s handling of custom implementations of ICompositeUserType. I changed my Composite User Types to IUserType (which is probably better suited for what the classes actually were), and it looks like Fluent NHibernate is cooperating now.
UPDATE #2: Adding an empty constructor does solve the problem – I’d mark this as answered, but the suggestion came in a comment instead of an answer, so I’m upvoting those comments (until an official answer is added).
Keep in mind that all Fluent NHibernate does is create the same configuration object structure that utilziing NHibernate XML would. How are you trying to set the ByteCodeProvider via Fluent NHibernate?