Tool to add INotifyPropertyChanged support to NHibernate's proxies, enabling their usage with WPF for example.
Two modes are available depending on whether your entity already implement INotifyPropertyChanged or not.
- Reference NHibernate.PropertyChanged.dll
- Configure your session factories with the proxy supplied in the library, PropertyChangedProxyFactoryFactory.
For example when using FluentNHibernate:
Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory().ShowSql())
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Person>()))
// just add this line
.ProxyFactoryFactory<PropertyChangedProxyFactoryFactory>()
.BuildSessionFactory();
- Reference NHibernate.PropertyChanged.dll
- Configure your session factories with the other proxy supplied in the library, AddPropertyChangedProxyFactoryFactory.
For example when using FluentNHibernate:
Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory().ShowSql())
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Person>()))
// just add these two lines
.ProxyFactoryFactory<AddPropertyChangedProxyFactoryFactory>()
.ExposeConfiguration(c => c.SetInterceptor(new AddPropertyChangedInterceptor()))
.BuildSessionFactory();
Note that with this method, since the entities themselves don't implement INotifyPropertyChanged, when you create a new entity, no PropertyChanged event will be available. To get a new entity that implements it, you will need to use the following factory:
var person = AddPropertyChangedInterceptorProxyFactory.Create<Person>();
When you save these entities, you will need to specify the entity name:
Session.SaveOrUpdate(typeof(Person).FullName, person);
Because of these complications, it is recommended to use the first method. If you don't want to implement INotifyPropertyChanged by hand, you can use a tool like PropertyChanged.Fody.
Based on the following posts:
http://weblogs.asp.net/ricardoperes/archive/2012/06/19/implementing-an-interceptor-using-nhibernate-s-built-in-dynamic-proxy-generator.aspx
http://ayende.com/blog/4106/nhibernate-inotifypropertychanged