Making event listeners serializable in order to be able to serialize NH's Configuration
Description
Environment
Attachments
Activity
Valeriu Caraulean December 5, 2010 at 9:53 AM
> The next time, please, try to be a little bit less ridiculous.
Most likely there will be no "next time".
I have required changes in my DVCS repository & just picking updates from official repo.
Anyway, thanks for applying the patch.
Fabio Maulo December 5, 2010 at 8:12 AM
The next time, please, try to be a little bit less ridiculous.
Thanks.
You don't know the statistic about NHV users/contributors so you don't know why we are using VS2008.
About DVCS, FYI the mayor part of OSS projects are using CVS, SVN statistic are available in OhlOh and SourceForge.
Valeriu Caraulean September 7, 2010 at 1:51 PM
Cheers guys. It's an absolute PITA to contribute:
VS2008.
Subversion
Good luck.
Valeriu Caraulean September 7, 2010 at 1:49 PM
Please ignore the patch:
it's not complete
it will not work for Subversion as it was generated from Mercurial changeset.
How to do the change manually:
Mark all 3 listeners - ValidateEventListener, ValidatePreUpdateEventListener, ValidatePreInsertEventListener with [Serializable] attribute.
Unit test, to be placed in NHibernate.Validator.Tests.Serialization folder:
[TestFixture]
public class EventListenersSerializationFixture
{
[Test]
public void AllEventListenersAreSerializable()
{
var listeners = GetListeners();
listeners.ForEach(x => Assert.That(x, Has.Attribute<SerializableAttribute>()));
}
[Test]
public void AllEventListenersCanBeSerialized()
{
var listeners = GetListeners();
foreach (var listener in listeners)
{
var listenerInstance = Activator.CreateInstance(listener);
Assert.That(listenerInstance, Is.BinarySerializable);
}
}
private static List<System.Type> GetListeners()
{
return typeof(ValidateEventListener).Assembly
.GetTypes()
.Where(type => typeof(ValidateEventListener).IsAssignableFrom(type))
.ToList();
}
}
Trying to serialize NHibernate.Cfg.Configuration object when configuration contains listeners registered by NHibernate.Validator an exception is thrown because NHV's listeners are not serializable.
I've added SerializableAttribute to all 3 listener classes.
Patch includes two unit tests.