forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultProxyFactory.cs
42 lines (37 loc) · 1.43 KB
/
DefaultProxyFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using NHibernate.Engine;
using NHibernate.Intercept;
using NHibernate.Proxy.DynamicProxy;
namespace NHibernate.Proxy
{
// Since v5.2
[Obsolete("Use StaticProxyFactory instead")]
public class DefaultProxyFactory : AbstractProxyFactory
{
private readonly ProxyFactory factory = new ProxyFactory();
protected static readonly INHibernateLogger log = NHibernateLogger.For(typeof (DefaultProxyFactory));
public override INHibernateProxy GetProxy(object id, ISessionImplementor session)
{
try
{
var initializer = new DefaultLazyInitializer(EntityName, PersistentClass, id, GetIdentifierMethod, SetIdentifierMethod, ComponentIdType, session, OverridesEquals);
object proxyInstance = IsClassProxy
? factory.CreateProxy(PersistentClass, initializer, Interfaces)
: factory.CreateProxy(Interfaces[0], initializer, Interfaces);
return (INHibernateProxy) proxyInstance;
}
catch (Exception ex)
{
log.Error(ex, "Creating a proxy instance failed");
throw new HibernateException("Creating a proxy instance failed", ex);
}
}
// Since 5.3
[Obsolete("Use ProxyFactoryExtensions.GetFieldInterceptionProxy extension method instead.")]
public override object GetFieldInterceptionProxy(object instanceToWrap)
{
var interceptor = new DefaultDynamicLazyFieldInterceptor();
return factory.CreateProxy(PersistentClass, interceptor, new[] { typeof(IFieldInterceptorAccessor) });
}
}
}