Is it possible to use the factory method to instantiate your class using free nhibernate?

For example, I have a set of domain classes. These classes implement a common interface. The interface is public, but the classes themselves are internal. Instances of these classes can be created using the provided factory, which is publicly available. In addition, each instance of the class is saved using the "one table per hierarchy" method.

How to use Fluent NHibernate in this case? Any help would be greatly appreciated.

Thanks Blake

+3
source share
2 answers

This is more NHibernate than FNH, but you have two options, as far as I can see.

, , , .

+2

NHibernate 2.0+. Load NHibernate. , , ILoadEventListener, ISessionFactory ISession !

 using NHibernate.Event.Default

 public class MyCreatorListener : DefaultLoadEventListener
 {
   // this is the single method defined by the LoadEventListener interface
   public override void OnLoad(LoadEvent theEvent, LoadType loadType)
   {
     if(null == theEvent.InstanceToLoad) // Not null if user supplied object
     {
       theEvent.InstanceToLoad = MyFactory.Create(loadType); // Or whatever.
     }
   }
 }
+1

Source: https://habr.com/ru/post/1786239/


All Articles