forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIProxyFactory.cs
124 lines (116 loc) · 4.13 KB
/
IProxyFactory.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.Reflection;
using NHibernate.Engine;
using NHibernate.Type;
namespace NHibernate.Proxy
{
/// <summary> Contract for run-time, proxy-based lazy initialization proxies. </summary>
public interface IProxyFactory
{
/// <summary> Called immediately after instantiation of this factory. </summary>
/// <param name="entityName">
/// The name of the entity for which this factory should generate proxies.
/// </param>
/// <param name="persistentClass">
/// The entity class for which to generate proxies; not always the same as the entityName.
/// </param>
/// <param name="interfaces">
/// The interfaces to expose in the generated proxy;
/// <see cref="INHibernateProxy"/> is already included in this collection.
/// </param>
/// <param name="getIdentifierMethod">
/// Reference to the identifier getter method; invocation on this method should not force initialization
/// </param>
/// <param name="setIdentifierMethod">
/// Reference to the identifier setter method; invocation on this method should not force initialization
/// </param>
/// <param name="componentIdType">
/// For composite identifier types, a reference to
/// the <see cref="ComponentType">type</see> of the identifier
/// property; again accessing the id should generally not cause
/// initialization - but need to bear in mind key-many-to-one
/// mappings.
/// </param>
/// <exception cref="HibernateException"> Indicates a problem completing post </exception>
/// <remarks>
/// Essentially equivalent to constructor injection, but contracted
/// here via interface.
/// </remarks>
//Since v5.3
[Obsolete("Use ProxyFactoryExtensions.PostInstantiate extension method instead.")]
void PostInstantiate(string entityName, System.Type persistentClass, ISet<System.Type> interfaces,
MethodInfo getIdentifierMethod, MethodInfo setIdentifierMethod, IAbstractComponentType componentIdType);
/// <summary>
/// Create a new proxy
/// </summary>
/// <param name="id">The id value for the proxy to be generated.</param>
/// <param name="session">The session to which the generated proxy will be associated.</param>
/// <returns>The generated proxy.</returns>
/// <exception cref="HibernateException">Indicates problems generating requested proxy.</exception>
INHibernateProxy GetProxy(object id, ISessionImplementor session);
// Since v5.3
[Obsolete("Use ProxyFactoryExtensions.GetFieldInterceptionProxy extension method instead.")]
object GetFieldInterceptionProxy(object instanceToWrap);
}
public static class ProxyFactoryExtensions
{
// 6.0 TODO: Remove
internal static object GetFieldInterceptionProxy(this IProxyFactory proxyFactory, Func<object> instantiateFunc)
{
if (proxyFactory is StaticProxyFactory staticProxyFactory)
{
return staticProxyFactory.GetFieldInterceptionProxy();
}
#pragma warning disable 618
return proxyFactory.GetFieldInterceptionProxy(instantiateFunc?.Invoke());
#pragma warning restore 618
}
// 6.0 TODO: Move to IProxyFactory
public static object GetFieldInterceptionProxy(this IProxyFactory proxyFactory)
{
if (proxyFactory is StaticProxyFactory staticProxyFactory)
{
return staticProxyFactory.GetFieldInterceptionProxy();
}
#pragma warning disable 618
return proxyFactory.GetFieldInterceptionProxy(null);
#pragma warning restore 618
}
// 6.0 TODO: Move to IProxyFactory
public static void PostInstantiate(
this IProxyFactory pf,
string entityName,
System.Type persistentClass,
HashSet<System.Type> interfaces,
MethodInfo getIdentifierMethod,
MethodInfo setIdentifierMethod,
IAbstractComponentType componentIdType,
bool isClassProxy)
{
if (pf is AbstractProxyFactory apf)
{
apf.PostInstantiate(
entityName,
persistentClass,
interfaces,
getIdentifierMethod,
setIdentifierMethod,
componentIdType,
isClassProxy);
}
else
{
#pragma warning disable 618
pf.PostInstantiate(
entityName,
persistentClass,
interfaces,
getIdentifierMethod,
setIdentifierMethod,
componentIdType);
#pragma warning restore 618
}
}
}
}