ProxyFactory.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using log4net;
  3. using NHibernate.Engine;
  4. using NHibernate.Proxy;
  5. namespace NHibernate.ByteCode.LinFu
  6. {
  7. public class ProxyFactory : AbstractProxyFactory
  8. {
  9. private static readonly global::LinFu.DynamicProxy.ProxyFactory factory = new global::LinFu.DynamicProxy.ProxyFactory();
  10. protected static readonly ILog log = LogManager.GetLogger(typeof (ProxyFactory));
  11. #region IProxyFactory Members
  12. public override INHibernateProxy GetProxy(object id, ISessionImplementor session)
  13. {
  14. try
  15. {
  16. var initializer = new LazyInitializer(EntityName, PersistentClass, id, GetIdentifierMethod, SetIdentifierMethod,
  17. ComponentIdType, session);
  18. object proxyInstance = IsClassProxy ? factory.CreateProxy(PersistentClass, initializer, Interfaces)
  19. : factory.CreateProxy(Interfaces[0], initializer, Interfaces);
  20. return (INHibernateProxy) proxyInstance;
  21. }
  22. catch (Exception ex)
  23. {
  24. log.Error("Creating a proxy instance failed", ex);
  25. throw new HibernateException("Creating a proxy instance failed", ex);
  26. }
  27. }
  28. #endregion
  29. }
  30. }