-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLLBLGenProODataServiceBase.cs
More file actions
236 lines (217 loc) · 8.3 KB
/
LLBLGenProODataServiceBase.cs
File metadata and controls
236 lines (217 loc) · 8.3 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
//////////////////////////////////////////////////////////////////////
// Part of the OData Support Classes for LLBLGen Pro.
// LLBLGen Pro is (c) 2002-2020 Solutions Design. All rights reserved.
// http://www.llblgen.com
//////////////////////////////////////////////////////////////////////
// The OData Support Classes sourcecode is released under the following license:
// --------------------------------------------------------------------------------------------
//
// The MIT License(MIT)
//
// Copyright (c)2002-2020 Solutions Design. All rights reserved.
// https://www.llblgen.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//////////////////////////////////////////////////////////////////////
// Contributers to the code:
// - Brian Chance
// - Frans Bouma [FB]
//////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Services;
using System.Data.Services.Providers;
using SD.LLBLGen.Pro.ORMSupportClasses;
namespace SD.LLBLGen.Pro.ODataSupportClasses
{
/// <summary>
/// Base class implementation for WCF Data Services dataservice classes using LLBLGen Pro.
/// </summary>
/// <typeparam name="TLinqMetaData">The type of the LinqMetaData class to use by the service</typeparam>
public abstract class LLBLGenProODataServiceBase<TLinqMetaData> : DataService<TLinqMetaData>, IServiceProvider
where TLinqMetaData : class, new()
{
#region Class Member Declarations
private LLBLGenProODataServiceMetadataProvider _modelMetadata;
private LLBLGenProODataQueryProvider<TLinqMetaData> _queryProvider;
private LLBLGenProODataServiceExpandProvider _expandProvider;
private LLBLGenProODataServiceUpdateProvider _updateProvider;
#endregion
/// <summary>
/// Creates a new TLinqMetaData instance.
/// </summary>
/// <returns>A ready to use TLinqMetaData instance</returns>
protected abstract TLinqMetaData CreateLinqMetaDataInstance();
/// <summary>
/// Creates a ready to use transaction controller. For Adapter, create a new DataAccessAdapter instance. For Selfservicing, create a new
/// Transaction instance.
/// </summary>
/// <returns>ready to use transaction controller.</returns>
protected abstract ITransactionController CreateTransactionControllerInstance();
/// <summary>
/// Creates a ready to use unit of work instance. For Adapter, create a new UnitOfWork2 instance. For SelfServicing, create a new
/// UnitOfWork instance.
/// </summary>
/// <returns>ready to use unit of work instance</returns>
protected abstract IUnitOfWorkCore CreateUnitOfWorkInstance();
/// <summary>
/// Gets the model meta data.
/// </summary>
/// <returns>ready to use ModelMetaData class</returns>
private LLBLGenProODataServiceMetadataProvider GetModelMetadata()
{
if(_modelMetadata == null)
{
_modelMetadata = MetaDataCache.GetInstance(this.GetType());
if(_modelMetadata == null)
{
// not yet in cache. Create new one.
var newModelMetadata = new LLBLGenProODataServiceMetadataProvider(this.GetType(), typeof(TLinqMetaData), this.ContainerName,
this.ContainerNamespace, this.AllowSubTypeNavigators);
_modelMetadata = MetaDataCache.AddInstance(this.GetType(), newModelMetadata);
}
}
return _modelMetadata;
}
/// <summary>
/// Gets the query provider.
/// </summary>
/// <returns></returns>
private IDataServiceQueryProvider GetQueryProvider()
{
if(_queryProvider == null)
{
_queryProvider = new LLBLGenProODataQueryProvider<TLinqMetaData>(this.Metadata, this) { CurrentDataSource = CreateLinqMetaDataInstance() };
}
return _queryProvider;
}
/// <summary>
/// Gets the expand provider.
/// </summary>
/// <returns></returns>
private LLBLGenProODataServiceExpandProvider GetExpandProvider()
{
if(_expandProvider == null)
{
_expandProvider = new LLBLGenProODataServiceExpandProvider();
}
return _expandProvider;
}
/// <summary>
/// Gets the update provider.
/// </summary>
/// <returns></returns>
private LLBLGenProODataServiceUpdateProvider GetUpdateProvider()
{
if(_updateProvider == null)
{
_updateProvider = new LLBLGenProODataServiceUpdateProvider(CreateUnitOfWorkInstance(), () => CreateTransactionControllerInstance(), this.Metadata);
}
return _updateProvider;
}
#region IServiceProvider Members
/// <summary>Returns service implementation.</summary>
/// <param name="serviceType">The type of the service requested.</param>
/// <returns>Implementation of such service or null.</returns>
public object GetService(Type serviceType)
{
if(serviceType == typeof(IDataServiceMetadataProvider))
{
return this.Metadata;
}
else if(serviceType == typeof(IDataServiceQueryProvider))
{
return this.QueryProvider;
}
// [FB] Commented out since June 2nd, 2013, because IExpandProvider is deprecated and it will cause WCF Data Services return
// less data. Not returning an IExpandProvider implementation will make the WCF Data Services construct nested queries, which are
// handled the same way as prefetch paths but will return the right set of data.
//
// else if(serviceType == typeof(IExpandProvider))
// {
// return this.ExpandProvider;
// }
else if(serviceType == typeof(IDataServiceUpdateProvider))
{
return this.UpdateProvider;
}
else
{
return null;
}
}
#endregion
#region Class Property Declarations
/// <summary>
/// Gets the query provider.
/// </summary>
protected virtual IDataServiceQueryProvider QueryProvider
{
get { return GetQueryProvider(); }
}
/// <summary>
/// Gets the meta data of the model represented by the service
/// </summary>
protected virtual LLBLGenProODataServiceMetadataProvider Metadata
{
get { return GetModelMetadata(); }
}
/// <summary>
/// Gets the expand provider.
/// </summary>
protected virtual LLBLGenProODataServiceExpandProvider ExpandProvider
{
get { return GetExpandProvider(); }
}
/// <summary>
/// Gets the update provider.
/// </summary>
protected virtual LLBLGenProODataServiceUpdateProvider UpdateProvider
{
get { return GetUpdateProvider(); }
}
/// <summary>
/// Gets the name of the container. This value is used for example when a proxy is generated by VS through Add Service Reference.
/// The main context class generated will have the ContainerName. By default it returns "LLBLGenProODataService"
/// </summary>
protected virtual string ContainerName
{
get { return "LLBLGenProODataService"; }
}
/// <summary>
/// Gets the container namespace. This is used in the $metadata response. By default it returns the namespace of the TLinqMetaData type.
/// </summary>
protected virtual string ContainerNamespace
{
get { return typeof(TLinqMetaData).Namespace; }
}
/// <summary>
/// Gets a value indicating whether subtype navigators are allowed (true, default) or not. As ODataSupportClasses is compiled against
/// an assembly which supports OData v3, the navigators of subtypes are by default allowed (OData v3 or higher). If you're communicating
/// with clients on OData v2, override this property and return false.
/// </summary>
protected virtual bool AllowSubTypeNavigators
{
get { return true; }
}
#endregion
}
}