-
Notifications
You must be signed in to change notification settings - Fork 936
/
Copy pathWcfOperationSessionContext.cs
91 lines (79 loc) · 2.58 KB
/
WcfOperationSessionContext.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
// There is no support of WCF Server under .Net Core, so it makes little sense to provide
// a WCF OperationContext for it. Since it adds additional heavy dependencies, it has been
// considered not desirable to provide it for .Net Standard. (It could be useful in case some
// WCF server becames available in another frameworks or if a .Net Framework application
// consumes the .Net Standard distribution of NHibernate instead of the .Net Framework one.)
// See https://github.com/dotnet/wcf/issues/1200 and #1842
#if NETFX
using System.Collections;
using System.ServiceModel;
using NHibernate.Engine;
namespace NHibernate.Context
{
/// <summary>
/// Provides a <see cref="ISessionFactory.GetCurrentSession()">current session</see>
/// for the current OperationContext in WCF. Works only during the lifetime of a WCF operation.
/// </summary>
public class WcfOperationSessionContext : MapBasedSessionContext
{
public WcfOperationSessionContext(ISessionFactoryImplementor factory) : base(factory) {}
private static WcfStateExtension WcfOperationState
{
get
{
var extension = OperationContext.Current.Extensions.Find<WcfStateExtension>();
if (extension == null)
{
extension = new WcfStateExtension();
OperationContext.Current.Extensions.Add(extension);
}
return extension;
}
}
protected override IDictionary GetMap()
{
return WcfOperationState.Map;
}
protected override void SetMap(IDictionary value)
{
WcfOperationState.Map = value;
}
}
public class WcfStateExtension : IExtension<OperationContext>
{
public IDictionary Map { get; set; }
// we don't really need implementations for these methods in this case
public void Attach(OperationContext owner) { }
public void Detach(OperationContext owner) { }
}
}
#else
// 6.0 TODO: remove the whole #else
using System;
using System.Collections;
using NHibernate.Engine;
namespace NHibernate.Context
{
/// <summary>
/// Obsolete class not usable with the current framework. Use the
/// .Net Framework distribution of NHibernate if you need it. See
/// https://github.com/nhibernate/nhibernate-core/issues/1842
/// </summary>
[Obsolete("Not supported in this platform", true)]
public class WcfOperationSessionContext : MapBasedSessionContext
{
public WcfOperationSessionContext(ISessionFactoryImplementor factory) : base(factory)
{
throw new PlatformNotSupportedException(
"WcfOperationSessionContext is not supported for the current framework");
}
protected override IDictionary GetMap()
{
return null;
}
protected override void SetMap(IDictionary value)
{
}
}
}
#endif