views:

28

answers:

1

I'm using NHibernate to map the following class to an Oracle database in my ASP.NET MVC application:

public class User
{
    // Needs to be encrypted/decrypted when persisting
    public virtual string Question { get; set; }
}

Following several examples that I've found, I would like to use an implementation of NHibernate's IUserType to transform my data when it is persisted to or retrieved from my database example.

Since I have already written an EncryptionService class to handle data encryption in other parts of my application, I would like to inject it into my user type. Is there a way to perform constructor injection on an IUserType using Autofac?

+1  A: 

NHibernate is responsible for creating instances of IUserType implementations. If you want this configurable, you could query the service from the AutoFac container (obviously this isn't dependency injection, more of service locator). Or you could implement IConfigurable, which allows you to take in a Dictionary of parameters. One of those parameters could be a class name.

Rich
That's what I have seen in all the examples I have read. I was hoping they were just outdated...
Justin R.