[my Blog]
Do you remember this post ?
As you can see you can use Dependency Injection even for entities, but what about all others classes needed by NHibernate ?
Can you inject something in a custom Dialect or in a custom UserType or UserCollectionType or Listener and all others extensions points ?
Sure you can ;)
NHibernate 2.1.0Alpha3, the fresh released today, has IObjectsFactory. As the ProxyFactoryFactory, the ReflectionOptimizer even the ObjectsFactory is a responsibility of the ByteCodeProvider.
To be short… an implementation of a IUserType now can look like this:
public class InjectableStringUserType : IUserType
{
private readonly IDelimiter delimiter;
public InjectableStringUserType(IDelimiter delimiter)
{
this.delimiter = delimiter;
}
The implementation of IPostInsertEventListener now can look like this:
public class YourPostInsertListener : IPostInsertEventListener
{
private readonly IPersistentAuditor auditor;
public YourPostInsertListener(IPersistentAuditor auditor)
{
this.auditor = auditor;
}
public void OnPostInsert(PostInsertEvent @event)
If you want use Dependency-Injection for both entities and all others NH stuff, in uNhAddIns you can find two full implementation for Castle and Spring.
Enjoy NHibernate injectability.
P.S. Part of it (tests), was a live implementation before start the Alt.NET VAN today.