diff --git a/src/GlobalSuppressions.cs b/src/GlobalSuppressions.cs index 52915e84..a8b1c1c1 100644 --- a/src/GlobalSuppressions.cs +++ b/src/GlobalSuppressions.cs @@ -9,8 +9,6 @@ [assembly: SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Scope = "type", Target = "Microsoft.Restier.Core.Submit.ChangeSetValidationException", Justification = "We do not intend to support serialization of this exception yet")] [assembly: SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.Batch.RestierBatchChangeSetRequestItem.#DisposeResponses(System.Collections.Generic.IEnumerable`1)")] [assembly: SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Scope = "member", Target = "Microsoft.Restier.Core.ApiBase.#Dispose()", Justification = "Need to do some clean up before the virtual Dispose(disposing) method gets called.")] -[assembly: SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Scope = "type", Target = "Microsoft.Restier.Core.ApiContext")] -[assembly: SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Scope = "member", Target = "Microsoft.Restier.Core.ApiContext.#Dispose()")] [assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames", Justification = "These assemblies are delay-signed.")] [assembly: SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Scope = "member", Target = "Microsoft.Restier.Providers.EntityFramework.ModelProducer.#ProduceModelAsync(Microsoft.Restier.Core.Model.ModelContext,System.Threading.CancellationToken)")] [assembly: SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Scope = "type", Target = "Microsoft.Restier.Core.Submit.ChangeSetValidationResults")] @@ -59,13 +57,10 @@ #region CA1026 Default Parameter [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.Batch.RestierBatchHandler.#.ctor(System.Web.Http.HttpServer,System.Func`1)")] [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Core.ApiBaseExtensions.#GetModelAsync(Microsoft.Restier.Core.ApiBase,System.Threading.CancellationToken)")] -[assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Core.ApiContextExtensions.#GetModelAsync(Microsoft.Restier.Core.ApiContext,System.Threading.CancellationToken)")] [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Core.ApiBaseExtensions.#QueryAsync`1(Microsoft.Restier.Core.ApiBase,System.Linq.IQueryable`1,System.Threading.CancellationToken)")] [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Core.ApiBaseExtensions.#QueryAsync`2(Microsoft.Restier.Core.ApiBase,System.Linq.IQueryable`1,System.Linq.Expressions.Expression`1,!!1>>,System.Threading.CancellationToken)")] [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Core.ApiBaseExtensions.#QueryAsync(Microsoft.Restier.Core.ApiBase,Microsoft.Restier.Core.Query.QueryRequest,System.Threading.CancellationToken)")] -[assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Core.ApiContextExtensions.#QueryAsync(Microsoft.Restier.Core.ApiContext,Microsoft.Restier.Core.Query.QueryRequest,System.Threading.CancellationToken)")] [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Core.ApiBaseExtensions.#SubmitAsync(Microsoft.Restier.Core.ApiBase,Microsoft.Restier.Core.Submit.ChangeSet,System.Threading.CancellationToken)")] -[assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Core.ApiContextExtensions.#SubmitAsync(Microsoft.Restier.Core.ApiContext,Microsoft.Restier.Core.Submit.ChangeSet,System.Threading.CancellationToken)")] [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Core.Query.QueryRequest.#.ctor(System.Linq.IQueryable,System.Nullable`1)")] [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Core.Query.QueryRequest.#Create`2(System.Linq.IQueryable`1,System.Linq.Expressions.Expression`1,!!1>>,System.Nullable`1)")] [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Core.Query.QueryRequest.#Create(System.Linq.IQueryable,System.Linq.Expressions.LambdaExpression,System.Nullable`1)")] @@ -74,7 +69,6 @@ [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Security.ApiPermission.#CreateDeny(System.String,System.String,System.String,System.String,System.String)")] [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.HttpConfigurationExtensions.#MapRestierRoute`1(System.Web.Http.HttpConfiguration,System.String,System.String,System.Func`1,Microsoft.Restier.Publishers.OData.Batch.RestierBatchHandler)")] [assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.HttpConfigurationExtensions.#MapRestierRoute`1(System.Web.Http.HttpConfiguration,System.String,System.String,Microsoft.Restier.Publishers.OData.Batch.RestierBatchHandler)")] -[assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.Batch.RestierBatchHandler.#.ctor(System.Web.Http.HttpServer,System.Func`1)")] [assembly: SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Scope = "type", Target = "Microsoft.Restier.Core.PreconditionFailedException")] [assembly: SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Scope = "type", Target = "Microsoft.Restier.Core.ResourceNotFoundException")] [assembly: SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Scope = "type", Target = "Microsoft.Restier.Core.PreconditionRequiredException")] @@ -116,7 +110,7 @@ [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.Model.RestierModelExtender+ModelMapper.#ModelCache")] [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.Model.RestierModelExtender+ModelMapper.#InnerModelMapper")] [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.BaseResult.#EdmType")] -[assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.BaseResult.#Context")] +[assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.BaseResult.#Api")] [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.PropertyAttributes.#NoWritePermission")] [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.PropertyAttributes.#NoReadPermission")] [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.PropertyAttributes.#NoReadPermission")] @@ -156,9 +150,6 @@ #endregion #region CA2208 Add string message for exception -[assembly: SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Microsoft.Restier.Core.ApiContextExtensions.#GetQueryableSource`1(Microsoft.Restier.Core.ApiContext,System.String,System.Object[])")] -[assembly: SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Microsoft.Restier.Core.ApiContextExtensions.#GetQueryableSource`1(Microsoft.Restier.Core.ApiContext,System.String,System.String,System.Object[])")] -[assembly: SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Microsoft.Restier.Core.ApiContext.#.ctor(Microsoft.Restier.Core.ApiConfiguration)")] [assembly: SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Microsoft.Restier.Core.QueryableSource.#System.Linq.IQueryProvider.CreateQuery`1(System.Linq.Expressions.Expression)")] [assembly: SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Microsoft.Restier.Core.QueryableSource.#System.Linq.IQueryProvider.CreateQuery(System.Linq.Expressions.Expression)")] [assembly: SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Scope = "member", Target = "Microsoft.Restier.Core.Model.ModelContext.#ResourceSetTypeMap")] diff --git a/src/Microsoft.Restier.Core/ApiBase.cs b/src/Microsoft.Restier.Core/ApiBase.cs index 7e73fb10..1290f246 100644 --- a/src/Microsoft.Restier.Core/ApiBase.cs +++ b/src/Microsoft.Restier.Core/ApiBase.cs @@ -26,7 +26,7 @@ public abstract class ApiBase : IDisposable private static Action emptyConfig = _ => { }; - private ApiContext apiContext; + private ApiConfiguration apiConfiguration; private IServiceProvider serviceProvider; /// @@ -52,31 +52,26 @@ public IServiceProvider ServiceProvider } /// - /// Gets the API context for this API. + /// Gets a value indicating whether this API has been disposed. + /// + public bool IsDisposed { get; private set; } + + /// + /// Gets the API configuration for this API. /// - public ApiContext Context + internal ApiConfiguration Configuration { get { - if (this.IsDisposed) + if (this.apiConfiguration == null) { - throw new ObjectDisposedException(this.GetType().FullName); + this.apiConfiguration = serviceProvider.GetService(); } - if (this.apiContext == null) - { - this.apiContext = serviceProvider.GetService(); - } - - return this.apiContext; + return this.apiConfiguration; } } - /// - /// Gets a value indicating whether this API has been disposed. - /// - public bool IsDisposed { get; private set; } - /// /// Configure services for this API. /// @@ -150,12 +145,6 @@ public void Dispose() } this.IsDisposed = true; - - if (this.apiContext != null) - { - this.apiContext = null; - } - GC.SuppressFinalize(this); } } diff --git a/src/Microsoft.Restier.Core/ApiContextExtensions.cs b/src/Microsoft.Restier.Core/ApiBaseExtensions.cs similarity index 79% rename from src/Microsoft.Restier.Core/ApiContextExtensions.cs rename to src/Microsoft.Restier.Core/ApiBaseExtensions.cs index fe138bd6..9dbef032 100644 --- a/src/Microsoft.Restier.Core/ApiContextExtensions.cs +++ b/src/Microsoft.Restier.Core/ApiBaseExtensions.cs @@ -20,11 +20,11 @@ namespace Microsoft.Restier.Core /// /// Represents the API engine and provides a set of static /// (Shared in Visual Basic) methods for interacting with objects - /// that implement . + /// that implement . /// - public static class ApiContextExtensions + public static class ApiBaseExtensions { - private static readonly MethodInfo SourceCoreMethod = typeof(ApiContextExtensions) + private static readonly MethodInfo SourceCoreMethod = typeof(ApiBaseExtensions) .GetMember("SourceCore", BindingFlags.NonPublic | BindingFlags.Static) .Cast().Single(m => m.IsGenericMethod); @@ -41,29 +41,29 @@ public static class ApiContextExtensions /// /// Gets a service instance. /// - /// - /// An API context. + /// + /// An API. /// /// The service type. /// The service instance. - public static T GetApiService(this ApiContext context) where T : class + public static T GetApiService(this ApiBase api) where T : class { - Ensure.NotNull(context, "context"); - return context.ServiceProvider.GetService(); + Ensure.NotNull(api, "api"); + return api.ServiceProvider.GetService(); } /// /// Gets all registered service instances. /// - /// - /// An API context. + /// + /// An API. /// /// The service type. /// The ordered collection of service instances. - public static IEnumerable GetApiServices(this ApiContext context) where T : class + public static IEnumerable GetApiServices(this ApiBase api) where T : class { - Ensure.NotNull(context, "context"); - return context.ServiceProvider.GetServices(); + Ensure.NotNull(api, "api"); + return api.ServiceProvider.GetServices(); } #endregion @@ -73,8 +73,8 @@ public static IEnumerable GetApiServices(this ApiContext context) where T /// /// Indicates if this object has a property. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of a property. @@ -83,9 +83,9 @@ public static IEnumerable GetApiServices(this ApiContext context) where T /// true if this object has the /// property; otherwise, false. /// - public static bool HasProperty(this ApiContext context, string name) + public static bool HasProperty(this ApiBase api, string name) { - return context.GetPropertyBag().HasProperty(name); + return api.GetPropertyBag().HasProperty(name); } /// @@ -94,8 +94,8 @@ public static bool HasProperty(this ApiContext context, string name) /// /// The type of the property. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of a property. @@ -103,16 +103,16 @@ public static bool HasProperty(this ApiContext context, string name) /// /// The value of the property. /// - public static T GetProperty(this ApiContext context, string name) + public static T GetProperty(this ApiBase api, string name) { - return context.GetPropertyBag().GetProperty(name); + return api.GetPropertyBag().GetProperty(name); } /// /// Gets a property. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of a property. @@ -120,16 +120,16 @@ public static T GetProperty(this ApiContext context, string name) /// /// The value of the property. /// - public static object GetProperty(this ApiContext context, string name) + public static object GetProperty(this ApiBase api, string name) { - return context.GetPropertyBag().GetProperty(name); + return api.GetPropertyBag().GetProperty(name); } /// /// Sets a property. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of a property. @@ -137,23 +137,23 @@ public static object GetProperty(this ApiContext context, string name) /// /// A value for the property. /// - public static void SetProperty(this ApiContext context, string name, object value) + public static void SetProperty(this ApiBase api, string name, object value) { - context.GetPropertyBag().SetProperty(name, value); + api.GetPropertyBag().SetProperty(name, value); } /// /// Clears a property. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of a property. /// - public static void ClearProperty(this ApiContext context, string name) + public static void ClearProperty(this ApiBase api, string name) { - context.GetPropertyBag().ClearProperty(name); + api.GetPropertyBag().ClearProperty(name); } #endregion @@ -163,8 +163,8 @@ public static void ClearProperty(this ApiContext context, string name) /// /// Asynchronously gets an API model using an API context. /// - /// - /// An API context. + /// + /// An API. /// /// /// An optional cancellation token. @@ -174,18 +174,18 @@ public static void ClearProperty(this ApiContext context, string name) /// operation whose result is the API model. /// public static async Task GetModelAsync( - this ApiContext context, + this ApiBase api, CancellationToken cancellationToken = default(CancellationToken)) { - Ensure.NotNull(context, "context"); + Ensure.NotNull(api, "api"); - var config = context.Configuration; + var config = api.Configuration; if (config.Model != null) { return config.Model; } - var builder = context.GetApiService(); + var builder = api.GetApiService(); if (builder == null) { throw new InvalidOperationException(Resources.ModelBuilderNotRegistered); @@ -200,7 +200,7 @@ public static async Task GetModelAsync( try { - var buildContext = new ModelContext(context.ServiceProvider); + var buildContext = new ModelContext(api.ServiceProvider); var model = await builder.GetModelAsync(buildContext, cancellationToken); source.SetResult(model); return model; @@ -224,8 +224,8 @@ public static async Task GetModelAsync( /// /// Gets a queryable source of data using an API context. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of an entity set, singleton or composable function import. @@ -249,21 +249,21 @@ public static async Task GetModelAsync( /// /// public static IQueryable GetQueryableSource( - this ApiContext context, + this ApiBase api, string name, params object[] arguments) { - Ensure.NotNull(context, "context"); + Ensure.NotNull(api, "api"); Ensure.NotNull(name, "name"); - return context.SourceCore(null, name, arguments); + return api.SourceCore(null, name, arguments); } /// /// Gets a queryable source of data using an API context. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of a namespace containing a composable function. @@ -289,16 +289,16 @@ public static IQueryable GetQueryableSource( /// /// public static IQueryable GetQueryableSource( - this ApiContext context, + this ApiBase api, string namespaceName, string name, params object[] arguments) { - Ensure.NotNull(context, "context"); + Ensure.NotNull(api, "api"); Ensure.NotNull(namespaceName, "namespaceName"); Ensure.NotNull(name, "name"); - return SourceCore(context, namespaceName, name, arguments); + return SourceCore(api, namespaceName, name, arguments); } /// @@ -307,8 +307,8 @@ public static IQueryable GetQueryableSource( /// /// The type of the elements in the queryable source. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of an entity set, singleton or composable function import. @@ -332,14 +332,14 @@ public static IQueryable GetQueryableSource( /// /// public static IQueryable GetQueryableSource( - this ApiContext context, + this ApiBase api, string name, params object[] arguments) { - Ensure.NotNull(context, "context"); + Ensure.NotNull(api, "api"); Ensure.NotNull(name, "name"); - var elementType = context.EnsureElementType(null, name); + var elementType = api.EnsureElementType(null, name); if (typeof(TElement) != elementType) { throw new ArgumentException(Resources.ElementTypeNotMatch); @@ -354,8 +354,8 @@ public static IQueryable GetQueryableSource( /// /// The type of the elements in the queryable source. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of a namespace containing a composable function. @@ -381,16 +381,16 @@ public static IQueryable GetQueryableSource( /// /// public static IQueryable GetQueryableSource( - this ApiContext context, + this ApiBase api, string namespaceName, string name, params object[] arguments) { - Ensure.NotNull(context, "context"); + Ensure.NotNull(api, "api"); Ensure.NotNull(namespaceName, "namespaceName"); Ensure.NotNull(name, "name"); - var elementType = context.EnsureElementType(namespaceName, name); + var elementType = api.EnsureElementType(namespaceName, name); if (typeof(TElement) != elementType) { throw new ArgumentException(Resources.ElementTypeNotMatch); @@ -406,8 +406,8 @@ public static IQueryable GetQueryableSource( /// /// Asynchronously queries for data using an API context. /// - /// - /// An API context. + /// + /// An API. /// /// /// A query request. @@ -420,15 +420,15 @@ public static IQueryable GetQueryableSource( /// operation whose result is a query result. /// public static async Task QueryAsync( - this ApiContext context, + this ApiBase api, QueryRequest request, CancellationToken cancellationToken = default(CancellationToken)) { - Ensure.NotNull(context, "context"); + Ensure.NotNull(api, "api"); Ensure.NotNull(request, "request"); - var queryContext = new QueryContext(context.ServiceProvider, request); - var model = await context.GetModelAsync(cancellationToken); + var queryContext = new QueryContext(api.ServiceProvider, request); + var model = await api.GetModelAsync(cancellationToken); queryContext.Model = model; return await DefaultQueryHandler.QueryAsync(queryContext, cancellationToken); } @@ -440,8 +440,8 @@ public static async Task QueryAsync( /// /// Asynchronously submits changes made using an API context. /// - /// - /// An API context. + /// + /// An API. /// /// /// A change set, or null to submit existing pending changes. @@ -454,13 +454,13 @@ public static async Task QueryAsync( /// operation whose result is a submit result. /// public static async Task SubmitAsync( - this ApiContext context, + this ApiBase api, ChangeSet changeSet = null, CancellationToken cancellationToken = default(CancellationToken)) { - Ensure.NotNull(context, "context"); + Ensure.NotNull(api, "api"); - var submitContext = new SubmitContext(context.ServiceProvider, changeSet); + var submitContext = new SubmitContext(api.ServiceProvider, changeSet); return await DefaultSubmitHandler.SubmitAsync(submitContext, cancellationToken); } @@ -469,12 +469,12 @@ public static async Task SubmitAsync( #region GetQueryableSource Private private static IQueryable SourceCore( - this ApiContext context, + this ApiBase api, string namespaceName, string name, object[] arguments) { - var elementType = context.EnsureElementType(namespaceName, name); + var elementType = api.EnsureElementType(namespaceName, name); var method = SourceCoreMethod.MakeGenericMethod(elementType); var args = new object[] { namespaceName, name, arguments }; return method.Invoke(null, args) as IQueryable; @@ -515,22 +515,22 @@ private static IQueryable SourceCore( } private static Type EnsureElementType( - this ApiContext context, + this ApiBase api, string namespaceName, string name) { Type elementType = null; - var mapper = context.GetApiService(); + var mapper = api.GetApiService(); if (mapper != null) { if (namespaceName == null) { - mapper.TryGetRelevantType(context, name, out elementType); + mapper.TryGetRelevantType(api, name, out elementType); } else { - mapper.TryGetRelevantType(context, namespaceName, name, out elementType); + mapper.TryGetRelevantType(api, namespaceName, name, out elementType); } } @@ -549,10 +549,10 @@ private static Type EnsureElementType( #region PropertyBag Private - private static PropertyBag GetPropertyBag(this ApiContext context) + private static PropertyBag GetPropertyBag(this ApiBase api) { - Ensure.NotNull(context, "context"); - return context.GetApiService(); + Ensure.NotNull(api, "api"); + return api.GetApiService(); } #endregion diff --git a/src/Microsoft.Restier.Core/ApiContext.cs b/src/Microsoft.Restier.Core/ApiContext.cs deleted file mode 100644 index 084a4be6..00000000 --- a/src/Microsoft.Restier.Core/ApiContext.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.Restier.Core -{ - /// - /// Represents context under which an API operates. - /// - /// - /// An API context is an instantiation of an API configuration. - /// - public class ApiContext : IDisposable - { - private IServiceProvider serviceProvider; - private ApiConfiguration apiConfiguration; - - /// - /// Initializes a new instance of the class. - /// - /// - /// The service provider. - /// - public ApiContext(IServiceProvider provider) - { - this.serviceProvider = provider; - } - - /// - /// Gets a value indicating whether this API context has been disposed. - /// - public bool IsDisposed { get; private set; } - - /// - /// Gets the API configuration for this API. - /// - internal ApiConfiguration Configuration - { - get - { - if (this.apiConfiguration == null) - { - this.apiConfiguration = serviceProvider.GetService(); - } - - return this.apiConfiguration; - } - } - - /// - /// Gets the which contains all services of this . - /// - internal IServiceProvider ServiceProvider - { - get { return this.serviceProvider; } - } - - /// - /// Performs application-defined tasks associated with - /// freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - if (this.IsDisposed) - { - return; - } - - this.IsDisposed = true; - - GC.SuppressFinalize(this); - } - } -} diff --git a/src/Microsoft.Restier.Core/Microsoft.Restier.Core.csproj b/src/Microsoft.Restier.Core/Microsoft.Restier.Core.csproj index 94769031..b42490ec 100644 --- a/src/Microsoft.Restier.Core/Microsoft.Restier.Core.csproj +++ b/src/Microsoft.Restier.Core/Microsoft.Restier.Core.csproj @@ -76,8 +76,7 @@ - - + diff --git a/src/Microsoft.Restier.Core/Model/IModelMapper.cs b/src/Microsoft.Restier.Core/Model/IModelMapper.cs index 93323a3c..b9afa1df 100644 --- a/src/Microsoft.Restier.Core/Model/IModelMapper.cs +++ b/src/Microsoft.Restier.Core/Model/IModelMapper.cs @@ -15,8 +15,8 @@ public interface IModelMapper /// Tries to get the relevant type of an entity /// set, singleton, or composable function import. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of an entity set, singleton or composable function import. @@ -48,15 +48,15 @@ public interface IModelMapper /// /// bool TryGetRelevantType( - ApiContext context, + ApiBase apiBase, string name, out Type relevantType); /// /// Tries to get the relevant type of a composable function. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of a namespace containing a composable function. @@ -85,7 +85,7 @@ bool TryGetRelevantType( /// /// bool TryGetRelevantType( - ApiContext context, + ApiBase apiBase, string namespaceName, string name, out Type relevantType); diff --git a/src/Microsoft.Restier.Core/RestierContainerBuilder.cs b/src/Microsoft.Restier.Core/RestierContainerBuilder.cs index 4160fc0a..4ae50a8c 100644 --- a/src/Microsoft.Restier.Core/RestierContainerBuilder.cs +++ b/src/Microsoft.Restier.Core/RestierContainerBuilder.cs @@ -104,8 +104,8 @@ internal IContainerBuilder AddRestierService() { Func modelFactory = sp => { - var context = sp.GetService(); - var model = context.GetModelAsync(default(CancellationToken)).Result; + var api = sp.GetService(); + var model = api.GetModelAsync(default(CancellationToken)).Result; return model; }; diff --git a/src/Microsoft.Restier.Core/ServiceCollectionExtensions.cs b/src/Microsoft.Restier.Core/ServiceCollectionExtensions.cs index 3e498df9..41f9bbe9 100644 --- a/src/Microsoft.Restier.Core/ServiceCollectionExtensions.cs +++ b/src/Microsoft.Restier.Core/ServiceCollectionExtensions.cs @@ -214,8 +214,7 @@ public static IServiceCollection AddCoreServices(this IServiceCollection service Ensure.NotNull(apiType, "apiType"); services.AddScoped(apiType, apiType) - .AddScoped(typeof(ApiBase), apiType) - .AddScoped(); + .AddScoped(typeof(ApiBase), apiType); services.TryAddSingleton(); diff --git a/src/Microsoft.Restier.Providers.EntityFramework/EntityFrameworkApi.cs b/src/Microsoft.Restier.Providers.EntityFramework/EntityFrameworkApi.cs index ed5117e5..b2cc2310 100644 --- a/src/Microsoft.Restier.Providers.EntityFramework/EntityFrameworkApi.cs +++ b/src/Microsoft.Restier.Providers.EntityFramework/EntityFrameworkApi.cs @@ -34,7 +34,7 @@ public class EntityFrameworkApi : ApiBase where T : DbContext /// Initializes a new instance of the class. /// /// - /// An containing all services of this . + /// An containing all services of this . /// public EntityFrameworkApi(IServiceProvider serviceProvider) : base(serviceProvider) { @@ -47,7 +47,7 @@ protected T DbContext { get { - return (T)this.Context.GetApiService(); + return (T)this.GetApiService(); } } @@ -59,7 +59,7 @@ protected T DbContext /// The Api type. /// /// - /// The with which to create an . + /// The with which to create all DI services. /// /// /// The . diff --git a/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelMapper.cs b/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelMapper.cs index d0b47a8c..8efb5368 100644 --- a/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelMapper.cs +++ b/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelMapper.cs @@ -35,8 +35,8 @@ public ModelMapper(Type dbContextType) /// Tries to get the relevant type of an entity /// set, singleton, or composable function import. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of an entity set, singleton or composable function import. @@ -50,7 +50,7 @@ public ModelMapper(Type dbContextType) /// provided; otherwise, false. /// public bool TryGetRelevantType( - ApiContext context, + ApiBase apiBase, string name, out Type relevantType) { @@ -77,8 +77,8 @@ public bool TryGetRelevantType( /// /// Tries to get the relevant type of a composable function. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of a namespace containing a composable function. @@ -95,7 +95,7 @@ public bool TryGetRelevantType( /// provided; otherwise, false. /// public bool TryGetRelevantType( - ApiContext context, + ApiBase apiBase, string namespaceName, string name, out Type relevantType) diff --git a/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelProducer.cs b/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelProducer.cs index 75d0e908..0baf332b 100644 --- a/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelProducer.cs +++ b/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelProducer.cs @@ -48,7 +48,7 @@ public Task GetModelAsync(ModelContext context, CancellationToken can Ensure.NotNull(context, "context"); #if EF7 - var dbContext = context.ApiContext.GetApiService(); + var dbContext = context.ServiceProvider.GetService(); context.ResourceSetTypeMap = dbContext.GetType().GetProperties() .Where(e => e.PropertyType.FindGenericType(typeof(DbSet<>)) != null) .ToDictionary(e => e.Name, e => e.PropertyType.GetGenericArguments()[0]); diff --git a/src/Microsoft.Restier.Providers.EntityFramework/Submit/ChangeSetInitializer.cs b/src/Microsoft.Restier.Providers.EntityFramework/Submit/ChangeSetInitializer.cs index f9f09e7e..ad8f2985 100644 --- a/src/Microsoft.Restier.Providers.EntityFramework/Submit/ChangeSetInitializer.cs +++ b/src/Microsoft.Restier.Providers.EntityFramework/Submit/ChangeSetInitializer.cs @@ -145,11 +145,11 @@ private static async Task FindResource( DataModificationItem item, CancellationToken cancellationToken) { - var apiContext = context.ServiceProvider.GetService(); - IQueryable query = apiContext.GetQueryableSource(item.ResourceSetName); + var apiBase = context.ServiceProvider.GetService(); + IQueryable query = apiBase.GetQueryableSource(item.ResourceSetName); query = item.ApplyTo(query); - QueryResult result = await apiContext.QueryAsync(new QueryRequest(query), cancellationToken); + QueryResult result = await apiBase.QueryAsync(new QueryRequest(query), cancellationToken); object resource = result.Results.SingleOrDefault(); if (resource == null) diff --git a/src/Microsoft.Restier.Publishers.OData/Batch/RestierBatchChangeSetRequestItem.cs b/src/Microsoft.Restier.Publishers.OData/Batch/RestierBatchChangeSetRequestItem.cs index 7d790cdf..8095c1c7 100644 --- a/src/Microsoft.Restier.Publishers.OData/Batch/RestierBatchChangeSetRequestItem.cs +++ b/src/Microsoft.Restier.Publishers.OData/Batch/RestierBatchChangeSetRequestItem.cs @@ -88,7 +88,7 @@ public override async Task SendRequestAsync( internal async Task SubmitChangeSet(HttpRequestMessage request, ChangeSet changeSet) { var requestContainer = request.GetRequestContainer(); - using (var api = requestContainer.GetService()) + using (var api = requestContainer.GetService()) { SubmitResult submitResults = await api.SubmitAsync(changeSet); } diff --git a/src/Microsoft.Restier.Publishers.OData/Extensions.cs b/src/Microsoft.Restier.Publishers.OData/Extensions.cs index 37fd3fc5..3e20a099 100644 --- a/src/Microsoft.Restier.Publishers.OData/Extensions.cs +++ b/src/Microsoft.Restier.Publishers.OData/Extensions.cs @@ -69,9 +69,9 @@ public static bool IsConcurrencyCheckEnabled(this IEdmModel model, IEdmEntitySet } public static IReadOnlyDictionary CreatePropertyDictionary( - this Delta entity, IEdmStructuredType edmType, ApiContext apiContext, bool isCreation) + this Delta entity, IEdmStructuredType edmType, ApiBase api, bool isCreation) { - var propertiesAttributes = RetrievePropertiesAttributes(edmType, apiContext); + var propertiesAttributes = RetrievePropertiesAttributes(edmType, api); Dictionary propertyValues = new Dictionary(); foreach (string propertyName in entity.GetChangedPropertyNames()) @@ -93,7 +93,7 @@ public static IReadOnlyDictionary CreatePropertyDictionary( var complexObj = value as EdmComplexObject; if (complexObj != null) { - value = CreatePropertyDictionary(complexObj, complexObj.ActualEdmType, apiContext, isCreation); + value = CreatePropertyDictionary(complexObj, complexObj.ActualEdmType, api, isCreation); } propertyValues.Add(propertyName, value); @@ -104,7 +104,7 @@ public static IReadOnlyDictionary CreatePropertyDictionary( } public static IDictionary RetrievePropertiesAttributes( - IEdmStructuredType edmType, ApiContext apiContext) + IEdmStructuredType edmType, ApiBase api) { IDictionary propertiesAttributes; if (typePropertiesAttributes.TryGetValue(edmType, out propertiesAttributes)) @@ -112,7 +112,7 @@ public static IDictionary RetrievePropertiesAttribut return propertiesAttributes; } - var model = apiContext.GetModelAsync().Result; + var model = api.GetModelAsync().Result; foreach (var property in edmType.DeclaredProperties) { var annotations = model.FindVocabularyAnnotations(property); @@ -164,7 +164,7 @@ public static IDictionary RetrievePropertiesAttribut return propertiesAttributes; } - public static Type GetClrType(this IEdmType edmType, ApiContext api) + public static Type GetClrType(this IEdmType edmType, ApiBase api) { IEdmModel edmModel = api.GetModelAsync().Result; diff --git a/src/Microsoft.Restier.Publishers.OData/Model/ModelMapper.cs b/src/Microsoft.Restier.Publishers.OData/Model/ModelMapper.cs index e141b2f5..92cf0b59 100644 --- a/src/Microsoft.Restier.Publishers.OData/Model/ModelMapper.cs +++ b/src/Microsoft.Restier.Publishers.OData/Model/ModelMapper.cs @@ -21,8 +21,8 @@ internal class ModelMapper : IModelMapper /// Tries to get the relevant type of an entity /// set, singleton, or composable function import. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of an entity set, singleton or composable function import. @@ -36,12 +36,12 @@ internal class ModelMapper : IModelMapper /// provided; otherwise, false. /// public bool TryGetRelevantType( - ApiContext context, + ApiBase api, string name, out Type relevantType) { // Cannot await as cannot make method async - var model = context.GetModelAsync().Result; + var model = api.GetModelAsync().Result; var element = model.EntityContainer.Elements.Where(e => e.Name == name).FirstOrDefault(); if (element != null) @@ -73,14 +73,14 @@ public bool TryGetRelevantType( } } - return InnerMapper.TryGetRelevantType(context, name, out relevantType); + return InnerMapper.TryGetRelevantType(api, name, out relevantType); } /// /// Tries to get the relevant type of a composable function. /// - /// - /// An API context. + /// + /// An API. /// /// /// The name of a namespace containing a composable function. @@ -97,7 +97,7 @@ public bool TryGetRelevantType( /// provided; otherwise, false. /// public bool TryGetRelevantType( - ApiContext context, + ApiBase api, string namespaceName, string name, out Type relevantType) diff --git a/src/Microsoft.Restier.Publishers.OData/Model/RestierModelExtender.cs b/src/Microsoft.Restier.Publishers.OData/Model/RestierModelExtender.cs index f689458b..67e975cb 100644 --- a/src/Microsoft.Restier.Publishers.OData/Model/RestierModelExtender.cs +++ b/src/Microsoft.Restier.Publishers.OData/Model/RestierModelExtender.cs @@ -372,12 +372,12 @@ public ModelMapper(RestierModelExtender modelCache) /// public bool TryGetRelevantType( - ApiContext context, + ApiBase api, string name, out Type relevantType) { if (this.InnerModelMapper != null && - this.InnerModelMapper.TryGetRelevantType(context, name, out relevantType)) + this.InnerModelMapper.TryGetRelevantType(api, name, out relevantType)) { return true; } @@ -403,13 +403,13 @@ public bool TryGetRelevantType( /// public bool TryGetRelevantType( - ApiContext context, + ApiBase api, string namespaceName, string name, out Type relevantType) { if (this.InnerModelMapper != null && - this.InnerModelMapper.TryGetRelevantType(context, namespaceName, name, out relevantType)) + this.InnerModelMapper.TryGetRelevantType(api, namespaceName, name, out relevantType)) { return true; } diff --git a/src/Microsoft.Restier.Publishers.OData/Properties/Resources.Designer.cs b/src/Microsoft.Restier.Publishers.OData/Properties/Resources.Designer.cs index fdb4e813..3c38b074 100644 --- a/src/Microsoft.Restier.Publishers.OData/Properties/Resources.Designer.cs +++ b/src/Microsoft.Restier.Publishers.OData/Properties/Resources.Designer.cs @@ -69,15 +69,6 @@ internal static string ArguementsCannotbeNull { } } - /// - /// Looks up a localized string similar to RestierBatchHandler was called without an ApiContext Factory.. - /// - internal static string BatchHandlerRequiresApiContextFactory { - get { - return ResourceManager.GetString("BatchHandlerRequiresApiContextFactory", resourceCulture); - } - } - /// /// Looks up a localized string similar to {0} cannot write an object of type '{1}'.. /// diff --git a/src/Microsoft.Restier.Publishers.OData/Properties/Resources.resx b/src/Microsoft.Restier.Publishers.OData/Properties/Resources.resx index 28c0fd27..a44bf8ee 100644 --- a/src/Microsoft.Restier.Publishers.OData/Properties/Resources.resx +++ b/src/Microsoft.Restier.Publishers.OData/Properties/Resources.resx @@ -120,9 +120,6 @@ The argument with name {0} cannot be null. - - RestierBatchHandler was called without an ApiContext Factory. - {0} cannot write an object of type '{1}'. diff --git a/src/Microsoft.Restier.Publishers.OData/Query/RestierQueryBuilder.cs b/src/Microsoft.Restier.Publishers.OData/Query/RestierQueryBuilder.cs index 47235f79..4d2f80a5 100644 --- a/src/Microsoft.Restier.Publishers.OData/Query/RestierQueryBuilder.cs +++ b/src/Microsoft.Restier.Publishers.OData/Query/RestierQueryBuilder.cs @@ -17,7 +17,7 @@ internal class RestierQueryBuilder { private const string DefaultNameOfParameterExpression = "currentValue"; - private readonly ApiContext apiContext; + private readonly ApiBase api; private readonly ODataPath path; private readonly IDictionary> handlers = new Dictionary>(); @@ -25,11 +25,11 @@ internal class RestierQueryBuilder private IQueryable queryable; private Type currentType; - public RestierQueryBuilder(ApiContext apiContext, ODataPath path) + public RestierQueryBuilder(ApiBase api, ODataPath path) { - Ensure.NotNull(apiContext, "apiContext"); + Ensure.NotNull(api, "api"); Ensure.NotNull(path, "path"); - this.apiContext = apiContext; + this.api = api; this.path = path; this.handlers[typeof(EntitySetSegment)] = this.HandleEntitySetPathSegment; @@ -139,7 +139,7 @@ private void HandleEntitySetPathSegment(ODataPathSegment segment) { var entitySetPathSegment = (EntitySetSegment)segment; var entitySet = entitySetPathSegment.EntitySet; - this.queryable = this.apiContext.GetQueryableSource(entitySet.Name, (object[])null); + this.queryable = this.api.GetQueryableSource(entitySet.Name, (object[])null); this.currentType = this.queryable.ElementType; } @@ -147,7 +147,7 @@ private void HandleSingletonPathSegment(ODataPathSegment segment) { var singletonPathSegment = (SingletonSegment)segment; var singleton = singletonPathSegment.Singleton; - this.queryable = this.apiContext.GetQueryableSource(singleton.Name, (object[])null); + this.queryable = this.api.GetQueryableSource(singleton.Name, (object[])null); this.currentType = this.queryable.ElementType; } @@ -274,7 +274,7 @@ private void HandleEntityTypeSegment(ODataPathSegment segment) if (edmType.TypeKind == EdmTypeKind.Entity) { - this.currentType = edmType.GetClrType(apiContext); + this.currentType = edmType.GetClrType(api); this.queryable = ExpressionHelpers.OfType(this.queryable, this.currentType); } } diff --git a/src/Microsoft.Restier.Publishers.OData/RestierController.cs b/src/Microsoft.Restier.Publishers.OData/RestierController.cs index 41653293..5fc952ff 100644 --- a/src/Microsoft.Restier.Publishers.OData/RestierController.cs +++ b/src/Microsoft.Restier.Publishers.OData/RestierController.cs @@ -44,24 +44,24 @@ public class RestierController : ODataController private const string IfMatchKey = "@IfMatchKey"; private const string IfNoneMatchKey = "@IfNoneMatchKey"; - private ApiContext apiContext; + private ApiBase api; private bool shouldReturnCount; private bool shouldWriteRawValue; /// /// Gets the API associated with this controller. /// - private ApiContext ApiContext + private ApiBase Api { get { - if (this.apiContext == null) + if (this.api == null) { var provider = Request.GetRequestContainer(); - this.apiContext = provider.GetService(); + this.api = provider.GetService(); } - return this.apiContext; + return this.api; } } @@ -162,12 +162,12 @@ public async Task Post(EdmEntityObject edmEntityObject, Cance DataModificationItem postItem = new DataModificationItem( entitySet.Name, - expectedEntityType.GetClrType(ApiContext), - actualEntityType.GetClrType(ApiContext), + expectedEntityType.GetClrType(Api), + actualEntityType.GetClrType(Api), DataModificationItemAction.Insert, null, null, - edmEntityObject.CreatePropertyDictionary(actualEntityType, apiContext, true)); + edmEntityObject.CreatePropertyDictionary(actualEntityType, api, true)); RestierChangeSetProperty changeSetProperty = this.Request.GetChangeSet(); if (changeSetProperty == null) @@ -175,7 +175,7 @@ public async Task Post(EdmEntityObject edmEntityObject, Cance ChangeSet changeSet = new ChangeSet(); changeSet.Entries.Add(postItem); - SubmitResult result = await ApiContext.SubmitAsync(changeSet, cancellationToken); + SubmitResult result = await Api.SubmitAsync(changeSet, cancellationToken); } else { @@ -241,7 +241,7 @@ public async Task Delete(CancellationToken cancellationToken) DataModificationItem deleteItem = new DataModificationItem( entitySet.Name, - path.EdmType.GetClrType(ApiContext), + path.EdmType.GetClrType(Api), null, DataModificationItemAction.Remove, RestierQueryBuilder.GetPathKeyValues(path), @@ -254,7 +254,7 @@ public async Task Delete(CancellationToken cancellationToken) ChangeSet changeSet = new ChangeSet(); changeSet.Entries.Add(deleteItem); - SubmitResult result = await ApiContext.SubmitAsync(changeSet, cancellationToken); + SubmitResult result = await Api.SubmitAsync(changeSet, cancellationToken); } else { @@ -391,12 +391,12 @@ private async Task Update( DataModificationItem updateItem = new DataModificationItem( entitySet.Name, - expectedEntityType.GetClrType(ApiContext), - actualEntityType.GetClrType(ApiContext), + expectedEntityType.GetClrType(Api), + actualEntityType.GetClrType(Api), DataModificationItemAction.Update, RestierQueryBuilder.GetPathKeyValues(path), propertiesInEtag, - edmEntityObject.CreatePropertyDictionary(actualEntityType, apiContext, false)); + edmEntityObject.CreatePropertyDictionary(actualEntityType, api, false)); updateItem.IsFullReplaceUpdateRequest = isFullReplaceUpdate; RestierChangeSetProperty changeSetProperty = this.Request.GetChangeSet(); @@ -405,7 +405,7 @@ private async Task Update( ChangeSet changeSet = new ChangeSet(); changeSet.Entries.Add(updateItem); - SubmitResult result = await ApiContext.SubmitAsync(changeSet, cancellationToken); + SubmitResult result = await Api.SubmitAsync(changeSet, cancellationToken); } else { @@ -428,13 +428,13 @@ private HttpResponseMessage CreateQueryResponse( { if (this.shouldReturnCount || this.shouldWriteRawValue) { - var rawResult = new RawResult(query, typeReference, this.ApiContext); + var rawResult = new RawResult(query, typeReference, this.Api); singleResult = rawResult; response = this.Request.CreateResponse(HttpStatusCode.OK, rawResult); } else { - var primitiveResult = new PrimitiveResult(query, typeReference, this.ApiContext); + var primitiveResult = new PrimitiveResult(query, typeReference, this.Api); singleResult = primitiveResult; response = this.Request.CreateResponse(HttpStatusCode.OK, primitiveResult); } @@ -442,7 +442,7 @@ private HttpResponseMessage CreateQueryResponse( if (typeReference.IsComplex()) { - var complexResult = new ComplexResult(query, typeReference, this.ApiContext); + var complexResult = new ComplexResult(query, typeReference, this.Api); singleResult = complexResult; response = this.Request.CreateResponse(HttpStatusCode.OK, complexResult); } @@ -451,13 +451,13 @@ private HttpResponseMessage CreateQueryResponse( { if (this.shouldWriteRawValue) { - var rawResult = new RawResult(query, typeReference, this.ApiContext); + var rawResult = new RawResult(query, typeReference, this.Api); singleResult = rawResult; response = this.Request.CreateResponse(HttpStatusCode.OK, rawResult); } else { - var enumResult = new EnumResult(query, typeReference, this.ApiContext); + var enumResult = new EnumResult(query, typeReference, this.Api); singleResult = enumResult; response = this.Request.CreateResponse(HttpStatusCode.OK, enumResult); } @@ -481,11 +481,11 @@ private HttpResponseMessage CreateQueryResponse( if (elementType.IsPrimitive() || elementType.IsEnum()) { return this.Request.CreateResponse( - HttpStatusCode.OK, new NonResourceCollectionResult(query, typeReference, this.ApiContext)); + HttpStatusCode.OK, new NonResourceCollectionResult(query, typeReference, this.Api)); } return this.Request.CreateResponse( - HttpStatusCode.OK, new ResourceSetResult(query, typeReference, this.ApiContext)); + HttpStatusCode.OK, new ResourceSetResult(query, typeReference, this.Api)); } var entityResult = query.SingleOrDefault(); @@ -528,7 +528,7 @@ private HttpResponseMessage CreateQueryResponse( private IQueryable GetQuery(ODataPath path) { - RestierQueryBuilder builder = new RestierQueryBuilder(this.ApiContext, path); + RestierQueryBuilder builder = new RestierQueryBuilder(this.Api, path); IQueryable queryable = builder.BuildQuery(); this.shouldReturnCount = builder.IsCountPathSegmentPresent; this.shouldWriteRawValue = builder.IsValuePathSegmentPresent; @@ -550,7 +550,7 @@ private IQueryable ApplyQueryOptions( } HttpRequestMessageProperties properties = this.Request.ODataProperties(); - var model = ApiContext.GetModelAsync().Result; + var model = Api.GetModelAsync().Result; ODataQueryContext queryContext = new ODataQueryContext(model, queryable.ElementType, path); ODataQueryOptions queryOptions = new ODataQueryOptions(queryContext, this.Request); @@ -567,7 +567,7 @@ private IQueryable ApplyQueryOptions( } // TODO GitHubIssue#41 : Ensure stable ordering for query - ODataQuerySettings settings = ApiContext.GetApiService(); + ODataQuerySettings settings = Api.GetApiService(); if (this.shouldReturnCount) { @@ -580,13 +580,13 @@ private IQueryable ApplyQueryOptions( if (queryOptions.Count != null && !applyCount) { RestierQueryExecutorOptions queryExecutorOptions = - ApiContext.GetApiService(); + Api.GetApiService(); queryExecutorOptions.IncludeTotalCount = queryOptions.Count.Value; queryExecutorOptions.SetTotalCount = value => properties.TotalCount = value; } // Validate query before apply, and query setting like MaxExpansionDepth can be customized here - ODataValidationSettings validationSettings = ApiContext.GetApiService(); + ODataValidationSettings validationSettings = Api.GetApiService(); queryOptions.Validate(validationSettings); // Entity count can NOT be evaluated at this point of time because the source @@ -610,7 +610,7 @@ private async Task ExecuteQuery(IQueryable queryable, CancellationTo ShouldReturnCount = this.shouldReturnCount }; - QueryResult queryResult = await ApiContext.QueryAsync(queryRequest, cancellationToken); + QueryResult queryResult = await Api.QueryAsync(queryRequest, cancellationToken); var result = queryResult.Results.AsQueryable(); return result; } @@ -639,8 +639,8 @@ private Task ExecuteOperationAsync( IQueryable bindingParameterValue, CancellationToken cancellationToken) { - var executor = ApiContext.GetApiService(); - var implementInstance = ApiContext.GetApiService(); + var executor = Api.GetApiService(); + var implementInstance = Api.GetApiService(); var context = new OperationContext( getParaValueFunc, @@ -680,7 +680,7 @@ private async Task> GetOriginalValues(IEdmEn } // return 428(Precondition Required) if entity requires concurrency check. - var model = await this.ApiContext.GetModelAsync(); + var model = await this.Api.GetModelAsync(); bool needEtag = model.IsConcurrencyCheckEnabled(entitySet); if (needEtag) { diff --git a/src/Microsoft.Restier.Publishers.OData/Results/BaseCollectionResult.cs b/src/Microsoft.Restier.Publishers.OData/Results/BaseCollectionResult.cs index 53b248f3..4f051397 100644 --- a/src/Microsoft.Restier.Publishers.OData/Results/BaseCollectionResult.cs +++ b/src/Microsoft.Restier.Publishers.OData/Results/BaseCollectionResult.cs @@ -18,9 +18,9 @@ internal abstract class BaseCollectionResult : BaseResult /// /// The query that returns a collection of objects. /// The EDM type reference of the objects. - /// The context where the action is executed. - protected BaseCollectionResult(IQueryable query, IEdmTypeReference edmType, ApiContext context) - : base(edmType, context) + /// The api instance where the action is executed. + protected BaseCollectionResult(IQueryable query, IEdmTypeReference edmType, ApiBase api) + : base(edmType, api) { Ensure.NotNull(query, "query"); diff --git a/src/Microsoft.Restier.Publishers.OData/Results/BaseResult.cs b/src/Microsoft.Restier.Publishers.OData/Results/BaseResult.cs index 9cd2c139..b3ffd3bc 100644 --- a/src/Microsoft.Restier.Publishers.OData/Results/BaseResult.cs +++ b/src/Microsoft.Restier.Publishers.OData/Results/BaseResult.cs @@ -18,14 +18,14 @@ internal abstract class BaseResult /// Initializes a new instance of the class. /// /// The EDM type reference of the OData result. - /// The context where the action is executed. - protected BaseResult(IEdmTypeReference edmType, ApiContext context) + /// The api instance where the action is executed. + protected BaseResult(IEdmTypeReference edmType, ApiBase api) { Ensure.NotNull(edmType, "edmType"); - Ensure.NotNull(context, "context"); + Ensure.NotNull(api, "api"); this.edmType = edmType; - this.Context = context; + this.Api = api; } /// @@ -42,6 +42,6 @@ public IEdmTypeReference EdmType /// /// Gets the context where the action is executed. /// - public ApiContext Context { get; private set; } + public ApiBase Api { get; private set; } } } diff --git a/src/Microsoft.Restier.Publishers.OData/Results/BaseSingleResult.cs b/src/Microsoft.Restier.Publishers.OData/Results/BaseSingleResult.cs index 9ab620ee..ccd83da9 100644 --- a/src/Microsoft.Restier.Publishers.OData/Results/BaseSingleResult.cs +++ b/src/Microsoft.Restier.Publishers.OData/Results/BaseSingleResult.cs @@ -19,9 +19,9 @@ internal abstract class BaseSingleResult : BaseResult /// /// The query that returns an object. /// The EDM type reference of the object. - /// The context where the action is executed. - protected BaseSingleResult(IQueryable query, IEdmTypeReference edmType, ApiContext context) - : base(edmType, context) + /// The api instance where the action is executed. + protected BaseSingleResult(IQueryable query, IEdmTypeReference edmType, ApiBase api) + : base(edmType, api) { Ensure.NotNull(query, "query"); diff --git a/src/Microsoft.Restier.Publishers.OData/Results/ComplexResult.cs b/src/Microsoft.Restier.Publishers.OData/Results/ComplexResult.cs index a8e26a0f..e2e9e684 100644 --- a/src/Microsoft.Restier.Publishers.OData/Results/ComplexResult.cs +++ b/src/Microsoft.Restier.Publishers.OData/Results/ComplexResult.cs @@ -17,9 +17,9 @@ internal class ComplexResult : BaseSingleResult /// /// The query that returns a complex value. /// The EDM type reference of the complex value. - /// The context where the action is executed. - public ComplexResult(IQueryable query, IEdmTypeReference edmType, ApiContext context) - : base(query, edmType, context) + /// The api instance where the action is executed. + public ComplexResult(IQueryable query, IEdmTypeReference edmType, ApiBase api) + : base(query, edmType, api) { } } diff --git a/src/Microsoft.Restier.Publishers.OData/Results/EnumResult.cs b/src/Microsoft.Restier.Publishers.OData/Results/EnumResult.cs index c76f8ce8..aa707768 100644 --- a/src/Microsoft.Restier.Publishers.OData/Results/EnumResult.cs +++ b/src/Microsoft.Restier.Publishers.OData/Results/EnumResult.cs @@ -17,9 +17,9 @@ internal class EnumResult : BaseSingleResult /// /// The query that returns a enum value. /// The EDM type reference of the enum value. - /// The context where the action is executed. - public EnumResult(IQueryable query, IEdmTypeReference edmType, ApiContext context) - : base(query, edmType, context) + /// The api instance where the action is executed. + public EnumResult(IQueryable query, IEdmTypeReference edmType, ApiBase api) + : base(query, edmType, api) { } } diff --git a/src/Microsoft.Restier.Publishers.OData/Results/NonResourceCollectionResult.cs b/src/Microsoft.Restier.Publishers.OData/Results/NonResourceCollectionResult.cs index 87ba973c..09c4b8e0 100644 --- a/src/Microsoft.Restier.Publishers.OData/Results/NonResourceCollectionResult.cs +++ b/src/Microsoft.Restier.Publishers.OData/Results/NonResourceCollectionResult.cs @@ -17,9 +17,9 @@ internal class NonResourceCollectionResult : BaseCollectionResult /// /// The query that returns a collection of non-entity or complex values. /// The EDM type reference of the values. - /// The context where the action is executed. - public NonResourceCollectionResult(IQueryable query, IEdmTypeReference edmType, ApiContext context) - : base(query, edmType, context) + /// The api instance where the action is executed. + public NonResourceCollectionResult(IQueryable query, IEdmTypeReference edmType, ApiBase api) + : base(query, edmType, api) { } } diff --git a/src/Microsoft.Restier.Publishers.OData/Results/PrimitiveResult.cs b/src/Microsoft.Restier.Publishers.OData/Results/PrimitiveResult.cs index 7cc4cec1..682f8da7 100644 --- a/src/Microsoft.Restier.Publishers.OData/Results/PrimitiveResult.cs +++ b/src/Microsoft.Restier.Publishers.OData/Results/PrimitiveResult.cs @@ -17,9 +17,9 @@ internal class PrimitiveResult : BaseSingleResult /// /// The query that returns a primitive value. /// The EDM type reference of the primitive value. - /// The context where the action is executed. - public PrimitiveResult(IQueryable query, IEdmTypeReference edmType, ApiContext context) - : base(query, edmType, context) + /// The api instance where the action is executed. + public PrimitiveResult(IQueryable query, IEdmTypeReference edmType, ApiBase api) + : base(query, edmType, api) { } } diff --git a/src/Microsoft.Restier.Publishers.OData/Results/RawResult.cs b/src/Microsoft.Restier.Publishers.OData/Results/RawResult.cs index fd7dede1..e23be841 100644 --- a/src/Microsoft.Restier.Publishers.OData/Results/RawResult.cs +++ b/src/Microsoft.Restier.Publishers.OData/Results/RawResult.cs @@ -17,9 +17,9 @@ internal class RawResult : BaseSingleResult /// /// The query that returns a primitive value. /// The EDM type reference of the primitive value. - /// The context where the action is executed. - public RawResult(IQueryable query, IEdmTypeReference edmType, ApiContext context) - : base(query, edmType, context) + /// The api instance where the action is executed. + public RawResult(IQueryable query, IEdmTypeReference edmType, ApiBase api) + : base(query, edmType, api) { } } diff --git a/src/Microsoft.Restier.Publishers.OData/Results/ResourceSetResult.cs b/src/Microsoft.Restier.Publishers.OData/Results/ResourceSetResult.cs index d8a36edc..db547184 100644 --- a/src/Microsoft.Restier.Publishers.OData/Results/ResourceSetResult.cs +++ b/src/Microsoft.Restier.Publishers.OData/Results/ResourceSetResult.cs @@ -17,9 +17,9 @@ internal class ResourceSetResult : BaseCollectionResult /// /// The query that returns a collection of resources. /// The EDM type reference of the entities or complex. - /// The context where the action is executed. - public ResourceSetResult(IQueryable query, IEdmTypeReference edmType, ApiContext context) - : base(query, edmType, context) + /// The api instance where the action is executed. + public ResourceSetResult(IQueryable query, IEdmTypeReference edmType, ApiBase api) + : base(query, edmType, api) { } } diff --git a/test/Microsoft.Restier.Core.Tests/Api.Tests.cs b/test/Microsoft.Restier.Core.Tests/Api.Tests.cs index 23f8d35d..bd3c3e6f 100644 --- a/test/Microsoft.Restier.Core.Tests/Api.Tests.cs +++ b/test/Microsoft.Restier.Core.Tests/Api.Tests.cs @@ -36,7 +36,7 @@ public Task GetModelAsync(ModelContext context, CancellationToken can private class TestModelMapper : IModelMapper { public bool TryGetRelevantType( - ApiContext context, + ApiBase context, string name, out Type relevantType) { relevantType = typeof(string); @@ -44,7 +44,7 @@ public bool TryGetRelevantType( } public bool TryGetRelevantType( - ApiContext context, + ApiBase context, string namespaceName, string name, out Type relevantType) { @@ -115,7 +115,7 @@ public void ApiSourceOfEntityContainerElementIsCorrect() { var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); - var api = provider.GetService(); + var api = provider.GetService(); var arguments = new object[0]; @@ -141,10 +141,9 @@ public void SourceOfEntityContainerElementThrowsIfNotMapped() var container = new RestierContainerBuilder(typeof(TestApiEmpty)); var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; var arguments = new object[0]; - Assert.Throws(() => context.GetQueryableSource("Test", arguments)); + Assert.Throws(() => api.GetQueryableSource("Test", arguments)); } [Fact] @@ -153,10 +152,9 @@ public void SourceOfEntityContainerElementIsCorrect() var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; var arguments = new object[0]; - var source = context.GetQueryableSource("Test", arguments); + var source = api.GetQueryableSource("Test", arguments); Assert.Equal(typeof(string), source.ElementType); Assert.True(source.Expression is MethodCallExpression); var methodCall = source.Expression as MethodCallExpression; @@ -177,7 +175,7 @@ public void ApiSourceOfComposableFunctionIsCorrect() { var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); - var api = provider.GetService(); + var api = provider.GetService(); var arguments = new object[0]; @@ -205,10 +203,9 @@ public void SourceOfComposableFunctionThrowsIfNotMapped() var container = new RestierContainerBuilder(typeof(TestApiEmpty)); var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; var arguments = new object[0]; - Assert.Throws(() => context.GetQueryableSource("Namespace", "Function", arguments)); + Assert.Throws(() => api.GetQueryableSource("Namespace", "Function", arguments)); } [Fact] @@ -218,10 +215,9 @@ public void SourceOfComposableFunctionIsCorrect() var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; var arguments = new object[0]; - var source = context.GetQueryableSource("Namespace", "Function", arguments); + var source = api.GetQueryableSource("Namespace", "Function", arguments); Assert.Equal(typeof(DateTime), source.ElementType); Assert.True(source.Expression is MethodCallExpression); var methodCall = source.Expression as MethodCallExpression; @@ -244,7 +240,7 @@ public void GenericApiSourceOfEntityContainerElementIsCorrect() { var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); - var api = provider.GetService(); + var api = provider.GetService(); var arguments = new object[0]; @@ -270,10 +266,9 @@ public void GenericSourceOfEntityContainerElementThrowsIfWrongType() var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; var arguments = new object[0]; - Assert.Throws(() => context.GetQueryableSource("Test", arguments)); + Assert.Throws(() => api.GetQueryableSource("Test", arguments)); } [Fact] @@ -283,10 +278,9 @@ public void GenericSourceOfEntityContainerElementIsCorrect() var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; var arguments = new object[0]; - var source = context.GetQueryableSource("Test", arguments); + var source = api.GetQueryableSource("Test", arguments); Assert.Equal(typeof(string), source.ElementType); Assert.True(source.Expression is MethodCallExpression); var methodCall = source.Expression as MethodCallExpression; @@ -311,7 +305,7 @@ public void GenericApiSourceOfComposableFunctionIsCorrect() var arguments = new object[0]; - var source = api.Context.GetQueryableSource( + var source = api.GetQueryableSource( "Namespace", "Function", arguments); Assert.Equal(typeof(DateTime), source.ElementType); Assert.True(source.Expression is MethodCallExpression); @@ -337,10 +331,9 @@ public void GenericSourceOfComposableFunctionThrowsIfWrongType() var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; var arguments = new object[0]; - Assert.Throws(() => context.GetQueryableSource("Namespace", "Function", arguments)); + Assert.Throws(() => api.GetQueryableSource("Namespace", "Function", arguments)); } [Fact] @@ -349,10 +342,10 @@ public void GenericSourceOfComposableFunctionIsCorrect() var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; + var arguments = new object[0]; - var source = context.GetQueryableSource("Namespace", "Function", arguments); + var source = api.GetQueryableSource("Namespace", "Function", arguments); Assert.Equal(typeof(DateTime), source.ElementType); Assert.True(source.Expression is MethodCallExpression); var methodCall = source.Expression as MethodCallExpression; @@ -376,9 +369,8 @@ public void SourceQueryableCannotGenericEnumerate() var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; - var source = context.GetQueryableSource("Test"); + var source = api.GetQueryableSource("Test"); Assert.Throws(() => source.GetEnumerator()); } @@ -388,9 +380,8 @@ public void SourceQueryableCannotEnumerate() var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; - var source = context.GetQueryableSource("Test"); + var source = api.GetQueryableSource("Test"); Assert.Throws(() => (source as IEnumerable).GetEnumerator()); } @@ -400,9 +391,8 @@ public void SourceQueryProviderCannotGenericExecute() var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; - var source = context.GetQueryableSource("Test"); + var source = api.GetQueryableSource("Test"); Assert.Throws(() => source.Provider.Execute(null)); } @@ -412,9 +402,8 @@ public void SourceQueryProviderCannotExecute() var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; - var source = context.GetQueryableSource("Test"); + var source = api.GetQueryableSource("Test"); Assert.Throws(() => source.Provider.Execute(null)); } @@ -423,7 +412,7 @@ public async Task ApiQueryAsyncWithQueryReturnsResults() { var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); - var api = provider.GetService(); + var api = provider.GetService(); var request = new QueryRequest(api.GetQueryableSource("Test")); var result = await api.QueryAsync(request); @@ -437,7 +426,7 @@ public async Task ApiQueryAsyncCorrectlyForwardsCall() { var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); - var api = provider.GetService(); + var api = provider.GetService(); var queryRequest = new QueryRequest( api.GetQueryableSource("Test")); @@ -451,7 +440,7 @@ public async Task ApiSubmitAsyncCorrectlyForwardsCall() { var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); - var api = provider.GetService(); + var api = provider.GetService(); var submitResult = await api.SubmitAsync(); Assert.NotNull(submitResult.CompletedChangeSet); diff --git a/test/Microsoft.Restier.Core.Tests/ApiBase.Tests.cs b/test/Microsoft.Restier.Core.Tests/ApiBase.Tests.cs index 5025baca..75b150ac 100644 --- a/test/Microsoft.Restier.Core.Tests/ApiBase.Tests.cs +++ b/test/Microsoft.Restier.Core.Tests/ApiBase.Tests.cs @@ -26,20 +26,15 @@ public TestApi(IServiceProvider serviceProvider) : base(serviceProvider) interface IService { ApiBase Api { get; } - - ApiContext Context { get; } } class Service : IService { public ApiBase Api { get; set; } - public ApiContext Context { get; set; } - - public Service(ApiBase api, ApiContext context) + public Service(ApiBase api) { Api = api; - Context = context; } } @@ -59,14 +54,9 @@ public void ApiAndApiContextCanBeInjectedByDI() var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; - var svc = context.GetApiService(); + var svc = api.GetApiService(); Assert.Same(svc.Api, api); - Assert.Same(svc.Context, context); - - api.Dispose(); - Assert.Throws(() => api.Context); } } } diff --git a/test/Microsoft.Restier.Core.Tests/ApiConfiguration.Tests.cs b/test/Microsoft.Restier.Core.Tests/ApiConfiguration.Tests.cs index 948274f3..4f4dd065 100644 --- a/test/Microsoft.Restier.Core.Tests/ApiConfiguration.Tests.cs +++ b/test/Microsoft.Restier.Core.Tests/ApiConfiguration.Tests.cs @@ -22,17 +22,17 @@ public void ConfigurationRegistersApiServicesCorrectly() var provider = container.BuildContainer(); var api = provider.GetService(); - Assert.Null(api.Context.GetApiService()); - Assert.Null(api.Context.GetApiService()); + Assert.Null(api.GetApiService()); + Assert.Null(api.GetApiService()); container = new RestierContainerBuilder(typeof(TestApiB)); var provider2 = container.BuildContainer(); var apiB = provider2.GetService(); - Assert.Same(TestApiB.serviceA, apiB.Context.GetApiService()); + Assert.Same(TestApiB.serviceA, apiB.GetApiService()); - var serviceBInstance = apiB.Context.GetApiService(); - var serviceBInterface = apiB.Context.GetApiService(); + var serviceBInstance = apiB.GetApiService(); + var serviceBInterface = apiB.GetApiService(); Assert.Equal(serviceBInstance, serviceBInterface); // AddService will call services.TryAddTransient @@ -51,7 +51,7 @@ public void ServiceChainTest() var provider = container.BuildContainer(); var api = provider.GetService(); - var handler = api.Context.GetApiService(); + var handler = api.GetApiService(); Assert.Equal("q2Pre_q1Pre_q1Post_q2Post_", handler.GetStr()); } diff --git a/test/Microsoft.Restier.Core.Tests/ApiContext.Tests.cs b/test/Microsoft.Restier.Core.Tests/ApiContext.Tests.cs index 2945a8f6..0f27420a 100644 --- a/test/Microsoft.Restier.Core.Tests/ApiContext.Tests.cs +++ b/test/Microsoft.Restier.Core.Tests/ApiContext.Tests.cs @@ -23,8 +23,7 @@ public void NewApiContextIsConfiguredCorrectly() var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; - Assert.NotNull(context); + Assert.NotNull(api); } } } diff --git a/test/Microsoft.Restier.Core.Tests/InvocationContext.Tests.cs b/test/Microsoft.Restier.Core.Tests/InvocationContext.Tests.cs index da0d681a..9358c91e 100644 --- a/test/Microsoft.Restier.Core.Tests/InvocationContext.Tests.cs +++ b/test/Microsoft.Restier.Core.Tests/InvocationContext.Tests.cs @@ -45,9 +45,8 @@ public void NewInvocationContextIsConfiguredCorrectly() var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); var api = provider.GetService(); - var apiContext = api.Context; var context = new InvocationContext(provider); - Assert.Same(apiContext, context.GetApiService()); + Assert.Same(api, context.GetApiService()); } [Fact] diff --git a/test/Microsoft.Restier.Core.Tests/Model/DefaultModelHandler.Tests.cs b/test/Microsoft.Restier.Core.Tests/Model/DefaultModelHandler.Tests.cs index 82859b35..ed0c3d99 100644 --- a/test/Microsoft.Restier.Core.Tests/Model/DefaultModelHandler.Tests.cs +++ b/test/Microsoft.Restier.Core.Tests/Model/DefaultModelHandler.Tests.cs @@ -125,9 +125,8 @@ public async Task GetModelUsingDefaultModelHandler() var container = new RestierContainerBuilder(typeof(TestApiA)); var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; - var model = await context.GetModelAsync(); + var model = await api.GetModelAsync(); Assert.Equal(4, model.SchemaElements.Count()); Assert.NotNull(model.SchemaElements .SingleOrDefault(e => e.Name == "TestName")); @@ -171,10 +170,9 @@ private static Task[] PrepareThreads(int count, IServiceProvider prov var scopedProvider = provider.GetRequiredService().CreateScope().ServiceProvider; var api = scopedProvider.GetService(); - var context = api.Context; try { - var model = context.GetModelAsync().Result; + var model = api.GetModelAsync().Result; source.SetResult(model); } catch (Exception e) diff --git a/test/Microsoft.Restier.Core.Tests/PropertyBag.Tests.cs b/test/Microsoft.Restier.Core.Tests/PropertyBag.Tests.cs index 70dfe2a0..d9e55bd0 100644 --- a/test/Microsoft.Restier.Core.Tests/PropertyBag.Tests.cs +++ b/test/Microsoft.Restier.Core.Tests/PropertyBag.Tests.cs @@ -15,23 +15,22 @@ public void PropertyBagManipulatesPropertiesCorrectly() var container = new RestierContainerBuilder(typeof(TestApi)); var provider = container.BuildContainer(); var api = provider.GetService(); - var context =api.Context; - - Assert.False(context.HasProperty("Test")); - Assert.Null(context.GetProperty("Test")); - Assert.Null(context.GetProperty("Test")); - Assert.Equal(default(int), context.GetProperty("Test")); - - context.SetProperty("Test", "Test"); - Assert.True(context.HasProperty("Test")); - Assert.Equal("Test", context.GetProperty("Test")); - Assert.Equal("Test", context.GetProperty("Test")); - - context.ClearProperty("Test"); - Assert.False(context.HasProperty("Test")); - Assert.Null(context.GetProperty("Test")); - Assert.Null(context.GetProperty("Test")); - Assert.Equal(default(int), context.GetProperty("Test")); + + Assert.False(api.HasProperty("Test")); + Assert.Null(api.GetProperty("Test")); + Assert.Null(api.GetProperty("Test")); + Assert.Equal(default(int), api.GetProperty("Test")); + + api.SetProperty("Test", "Test"); + Assert.True(api.HasProperty("Test")); + Assert.Equal("Test", api.GetProperty("Test")); + Assert.Equal("Test", api.GetProperty("Test")); + + api.ClearProperty("Test"); + Assert.False(api.HasProperty("Test")); + Assert.Null(api.GetProperty("Test")); + Assert.Null(api.GetProperty("Test")); + Assert.Equal(default(int), api.GetProperty("Test")); } [Fact] @@ -41,9 +40,8 @@ public void DifferentPropertyBagsDoNotConflict() var provider = container.BuildContainer(); var api = provider.GetService(); - var context = api.Context; - context.SetProperty("Test", 2); - Assert.Equal(2, context.GetProperty("Test")); + api.SetProperty("Test", 2); + Assert.Equal(2, api.GetProperty("Test")); } [Fact] @@ -54,16 +52,14 @@ public void PropertyBagsAreDisposedCorrectly() var scope = provider.GetRequiredService().CreateScope(); var scopedProvider = scope.ServiceProvider; var api = scopedProvider.GetService(); - var context = api.Context; - Assert.NotNull(context.GetApiService()); + Assert.NotNull(api.GetApiService()); Assert.Equal(1, MyPropertyBag.InstanceCount); var scopedProvider2 = provider.GetRequiredService().CreateScope().ServiceProvider; var api2 = scopedProvider2.GetService(); - var context2 = api2.Context; - Assert.NotNull(context2.GetApiService()); + Assert.NotNull(api2.GetApiService()); Assert.Equal(2, MyPropertyBag.InstanceCount); scope.Dispose(); @@ -74,7 +70,7 @@ public void PropertyBagsAreDisposedCorrectly() /// /// has the same lifetime as PropertyBag thus /// use this class to test the lifetime of PropertyBag in ApiConfiguration - /// and ApiContext. + /// and ApiBase. /// private class MyPropertyBag : IDisposable { diff --git a/test/Microsoft.Restier.Core.Tests/ServiceConfiguration.Tests.cs b/test/Microsoft.Restier.Core.Tests/ServiceConfiguration.Tests.cs index c1689f19..c1bbe5f6 100644 --- a/test/Microsoft.Restier.Core.Tests/ServiceConfiguration.Tests.cs +++ b/test/Microsoft.Restier.Core.Tests/ServiceConfiguration.Tests.cs @@ -237,7 +237,7 @@ public string Call() private class SomeService2 : ISomeService { private string _value; - // The string value will be retrieved via api.Context.GetApiService() + // The string value will be retrieved via api.GetApiService() public SomeService2(string value = "4") { _value = value; @@ -340,7 +340,7 @@ public void ContributorsAreCalledCorrectly() var container = new RestierContainerBuilder(typeof(TestApiA)); var provider = container.BuildContainer(); var api = provider.GetService(); - var value = api.Context.GetApiService().Call(); + var value = api.GetApiService().Call(); Assert.Equal("03210", value); } @@ -350,11 +350,11 @@ public void NextInjectedViaProperty() var container = new RestierContainerBuilder(typeof(TestApiB)); var provider = container.BuildContainer(); var api = provider.GetService(); - var value = api.Context.GetApiService().Call(); + var value = api.GetApiService().Call(); Assert.Equal("01", value); // Test expression compilation. - value = api.Context.GetApiService().Call(); + value = api.GetApiService().Call(); Assert.Equal("01", value); } @@ -365,20 +365,20 @@ public void ContextApiScopeWorksCorrectly() var provider = container.BuildContainer(); var api = provider.GetService(); - var service1 = api.Context.GetApiService(); + var service1 = api.GetApiService(); container = new RestierContainerBuilder(typeof(TestApiC)); provider = container.BuildContainer(); var api2 = provider.GetService(); - var service2 = api2.Context.GetApiService(); + var service2 = api2.GetApiService(); Assert.NotEqual(service1, service2); container = new RestierContainerBuilder(typeof(TestApiC)); provider = container.BuildContainer(); var api3 = provider.GetService(); - var service3 = api3.Context.GetApiService(); + var service3 = api3.GetApiService(); Assert.NotEqual(service3, service2); } @@ -391,13 +391,13 @@ public void NothingInjectedStillWorks() var provider = container.BuildContainer(); var api = provider.GetService(); - var value = api.Context.GetApiService().Call(); + var value = api.GetApiService().Call(); Assert.Equal("42", value); // Test expression compilation. - value = api.Context.GetApiService().Call(); + value = api.GetApiService().Call(); Assert.Equal("42", value); - value = api.Context.GetApiService().Call(); + value = api.GetApiService().Call(); Assert.Equal("42", value); } @@ -409,18 +409,18 @@ public void ServiceInjectedViaProperty() var api = provider.GetService(); var expected = "Text42"; - var value = api.Context.GetApiService().Call(); + var value = api.GetApiService().Call(); Assert.Equal(expected, value); - value = api.Context.GetApiService().Call(); + value = api.GetApiService().Call(); Assert.Equal(expected, value); - value = api.Context.GetApiService().Call(); + value = api.GetApiService().Call(); Assert.Equal(expected, value); Assert.NotEqual( - api.Context.GetApiService(), - api.Context.GetApiService()); + api.GetApiService(), + api.GetApiService()); } [Fact] @@ -430,12 +430,12 @@ public void DefaultValueInConstructorUsedIfNoService() var provider = container.BuildContainer(); var api = provider.GetService(); - var value = api.Context.GetApiService().Call(); + var value = api.GetApiService().Call(); Assert.Equal("42", value); - value = api.Context.GetApiService().Call(); + value = api.GetApiService().Call(); Assert.Equal("42", value); - value = api.Context.GetApiService().Call(); + value = api.GetApiService().Call(); Assert.Equal("42", value); } @@ -447,13 +447,13 @@ public void MultiInjectionViaConstructor() var provider = container.BuildContainer(); var api = provider.GetService(); - var value = api.Context.GetApiService().Call(); + var value = api.GetApiService().Call(); Assert.Equal("0122", value); // Test expression compilation - value = api.Context.GetApiService().Call(); + value = api.GetApiService().Call(); Assert.Equal("0122", value); - value = api.Context.GetApiService().Call(); + value = api.GetApiService().Call(); Assert.Equal("0122", value); } @@ -464,7 +464,7 @@ public void ThrowOnNoServiceFound() var provider = container.BuildContainer(); var api = provider.GetService(); - Assert.Throws(() => { api.Context.GetApiService(); }); + Assert.Throws(() => { api.GetApiService(); }); } [Fact] @@ -474,13 +474,13 @@ public void NextInjectedWithInheritedField() var provider = container.BuildContainer(); var api = provider.GetService(); - var value = api.Context.GetApiService().Call(); + var value = api.GetApiService().Call(); Assert.Equal("4200", value); // Test expression compilation - value = api.Context.GetApiService().Call(); + value = api.GetApiService().Call(); Assert.Equal("4200", value); - value = api.Context.GetApiService().Call(); + value = api.GetApiService().Call(); Assert.Equal("4200", value); } } diff --git a/test/Microsoft.Restier.Providers.EntityFramework.Tests/ChangeSetPreparerTests.cs b/test/Microsoft.Restier.Providers.EntityFramework.Tests/ChangeSetPreparerTests.cs index e22d1ba3..47dd542f 100644 --- a/test/Microsoft.Restier.Providers.EntityFramework.Tests/ChangeSetPreparerTests.cs +++ b/test/Microsoft.Restier.Providers.EntityFramework.Tests/ChangeSetPreparerTests.cs @@ -35,7 +35,7 @@ public async Task ComplexTypeUpdate() var sc = new SubmitContext(provider, changeSet); // Act - var changeSetPreparer = libraryApi.Context.GetApiService(); + var changeSetPreparer = libraryApi.GetApiService(); await changeSetPreparer.InitializeAsync(sc, CancellationToken.None); var person = item.Resource as Person; diff --git a/test/Microsoft.Restier.Publishers.OData.Test/FallbackTests.cs b/test/Microsoft.Restier.Publishers.OData.Test/FallbackTests.cs index fe4daaa6..16fc19e0 100644 --- a/test/Microsoft.Restier.Publishers.OData.Test/FallbackTests.cs +++ b/test/Microsoft.Restier.Publishers.OData.Test/FallbackTests.cs @@ -108,7 +108,7 @@ internal class FallbackApi : ApiBase [Resource] public IQueryable PreservedOrders { - get { return this.Context.GetQueryableSource("Orders").Where(o => o.Id > 123); } + get { return this.GetQueryableSource("Orders").Where(o => o.Id > 123); } } public FallbackApi(IServiceProvider serviceProvider) : base(serviceProvider) @@ -174,14 +174,14 @@ public Expression ReplaceQueryableSource(QueryExpressionContext context, bool em class FallbackModelMapper : IModelMapper { - public bool TryGetRelevantType(ApiContext context, string name, out Type relevantType) + public bool TryGetRelevantType(ApiBase context, string name, out Type relevantType) { relevantType = name == "Person" ? typeof(Person) : typeof(Order); return true; } - public bool TryGetRelevantType(ApiContext context, string namespaceName, string name, out Type relevantType) + public bool TryGetRelevantType(ApiBase context, string namespaceName, string name, out Type relevantType) { return TryGetRelevantType(context, name, out relevantType); } diff --git a/test/Microsoft.Restier.Publishers.OData.Test/Model/RestierModelBuilderTests.cs b/test/Microsoft.Restier.Publishers.OData.Test/Model/RestierModelBuilderTests.cs index 34afa351..3867e013 100644 --- a/test/Microsoft.Restier.Publishers.OData.Test/Model/RestierModelBuilderTests.cs +++ b/test/Microsoft.Restier.Publishers.OData.Test/Model/RestierModelBuilderTests.cs @@ -20,7 +20,7 @@ public void ComplexTypeShoudWork() var provider = container.BuildContainer(); var api = provider.GetService(); - var model = api.Context.GetModelAsync().Result; + var model = api.GetModelAsync().Result; IEnumerable errors; Assert.True(model.Validate(out errors)); @@ -38,7 +38,7 @@ public void PrimitiveTypesShouldWork() var container = new RestierContainerBuilder(typeof(LibraryApi)); var provider = container.BuildContainer(); var api = provider.GetService(); - var model = api.Context.GetModelAsync().Result; + var model = api.GetModelAsync().Result; IEnumerable errors; Assert.True(model.Validate(out errors)); diff --git a/test/Microsoft.Restier.Publishers.OData.Test/Model/RestierModelExtender.Tests.cs b/test/Microsoft.Restier.Publishers.OData.Test/Model/RestierModelExtender.Tests.cs index cf71001b..a72c81c0 100644 --- a/test/Microsoft.Restier.Publishers.OData.Test/Model/RestierModelExtender.Tests.cs +++ b/test/Microsoft.Restier.Publishers.OData.Test/Model/RestierModelExtender.Tests.cs @@ -30,7 +30,6 @@ public async Task ApiModelBuilderShouldProduceCorrectModelForBasicScenario() { var model = await this.GetModelAsync(); Assert.DoesNotContain("ApiConfiguration", model.EntityContainer.Elements.Select(e => e.Name)); - Assert.DoesNotContain("ApiContext", model.EntityContainer.Elements.Select(e => e.Name)); Assert.DoesNotContain("Invisible", model.EntityContainer.Elements.Select(e => e.Name)); Assert.NotNull(model.EntityContainer.FindEntitySet("People")); Assert.NotNull(model.EntityContainer.FindSingleton("Me")); @@ -41,7 +40,6 @@ public async Task ApiModelBuilderShouldProduceCorrectModelForDerivedApi() { var model = await this.GetModelAsync(); Assert.DoesNotContain("ApiConfiguration", model.EntityContainer.Elements.Select(e => e.Name)); - Assert.DoesNotContain("ApiContext", model.EntityContainer.Elements.Select(e => e.Name)); Assert.DoesNotContain("Invisible", model.EntityContainer.Elements.Select(e => e.Name)); Assert.NotNull(model.EntityContainer.FindEntitySet("People")); Assert.NotNull(model.EntityContainer.FindEntitySet("Customers")); @@ -53,7 +51,6 @@ public async Task ApiModelBuilderShouldProduceCorrectModelForOverridingProperty( { var model = await this.GetModelAsync(); Assert.DoesNotContain("ApiConfiguration", model.EntityContainer.Elements.Select(e => e.Name)); - Assert.DoesNotContain("ApiContext", model.EntityContainer.Elements.Select(e => e.Name)); Assert.DoesNotContain("Invisible", model.EntityContainer.Elements.Select(e => e.Name)); Assert.NotNull(model.EntityContainer.FindEntitySet("People")); Assert.Equal("Customer", model.EntityContainer.FindEntitySet("Customers").EntityType().Name); @@ -65,7 +62,6 @@ public async Task ApiModelBuilderShouldProduceCorrectModelForIgnoringInheritedPr { var model = await this.GetModelAsync(); Assert.DoesNotContain("ApiConfiguration", model.EntityContainer.Elements.Select(e => e.Name)); - Assert.DoesNotContain("ApiContext", model.EntityContainer.Elements.Select(e => e.Name)); Assert.DoesNotContain("Invisible", model.EntityContainer.Elements.Select(e => e.Name)); Assert.Equal("Customer", model.EntityContainer.FindEntitySet("Customers").EntityType().Name); Assert.Equal("Customer", model.EntityContainer.FindSingleton("Me").EntityType().Name); @@ -140,7 +136,7 @@ await config.MapRestierRoute( var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/test"); request.SetConfiguration(config); var api = request.CreateRequestContainer("test").GetService(); - return await api.Context.GetModelAsync(); + return await api.GetModelAsync(); } } diff --git a/test/Microsoft.Restier.Publishers.OData.Test/StoreApi.cs b/test/Microsoft.Restier.Publishers.OData.Test/StoreApi.cs index 9dbdaeeb..aaf1980e 100644 --- a/test/Microsoft.Restier.Publishers.OData.Test/StoreApi.cs +++ b/test/Microsoft.Restier.Publishers.OData.Test/StoreApi.cs @@ -83,7 +83,7 @@ class Address class TestModelMapper : IModelMapper { - public bool TryGetRelevantType(ApiContext context, string name, out Type relevantType) + public bool TryGetRelevantType(ApiBase context, string name, out Type relevantType) { if (name == "Products") { @@ -105,7 +105,7 @@ public bool TryGetRelevantType(ApiContext context, string name, out Type relevan return true; } - public bool TryGetRelevantType(ApiContext context, string namespaceName, string name, out Type relevantType) + public bool TryGetRelevantType(ApiBase context, string namespaceName, string name, out Type relevantType) { relevantType = typeof(Product); return true; diff --git a/test/Microsoft.Restier.TestCommon/PublicApi.bsl b/test/Microsoft.Restier.TestCommon/PublicApi.bsl index 95cda4b4..3aeb1638 100644 --- a/test/Microsoft.Restier.TestCommon/PublicApi.bsl +++ b/test/Microsoft.Restier.TestCommon/PublicApi.bsl @@ -1,7 +1,6 @@ public abstract class Microsoft.Restier.Core.ApiBase : IDisposable { protected ApiBase (System.IServiceProvider serviceProvider) - Microsoft.Restier.Core.ApiContext Context { public get; } bool IsDisposed { [CompilerGeneratedAttribute(),]public get; } System.IServiceProvider ServiceProvider { public get; } @@ -25,79 +24,79 @@ public abstract class Microsoft.Restier.Core.ApiBase : IDisposable { [ ExtensionAttribute(), ] -public sealed class Microsoft.Restier.Core.ApiContextExtensions { +public sealed class Microsoft.Restier.Core.ApiBaseExtensions { [ ExtensionAttribute(), ] - public static void ClearProperty (Microsoft.Restier.Core.ApiContext context, string name) + public static void ClearProperty (Microsoft.Restier.Core.ApiBase api, string name) [ ExtensionAttribute(), ] - public static T GetApiService (Microsoft.Restier.Core.ApiContext context) + public static T GetApiService (Microsoft.Restier.Core.ApiBase api) [ ExtensionAttribute(), ] - public static IEnumerable`1 GetApiServices (Microsoft.Restier.Core.ApiContext context) + public static IEnumerable`1 GetApiServices (Microsoft.Restier.Core.ApiBase api) [ AsyncStateMachineAttribute(), ExtensionAttribute(), ] - public static System.Threading.Tasks.Task`1[[Microsoft.OData.Edm.IEdmModel]] GetModelAsync (Microsoft.Restier.Core.ApiContext context, params System.Threading.CancellationToken cancellationToken) + public static System.Threading.Tasks.Task`1[[Microsoft.OData.Edm.IEdmModel]] GetModelAsync (Microsoft.Restier.Core.ApiBase api, params System.Threading.CancellationToken cancellationToken) [ ExtensionAttribute(), ] - public static object GetProperty (Microsoft.Restier.Core.ApiContext context, string name) + public static object GetProperty (Microsoft.Restier.Core.ApiBase api, string name) [ ExtensionAttribute(), ] - public static T GetProperty (Microsoft.Restier.Core.ApiContext context, string name) + public static T GetProperty (Microsoft.Restier.Core.ApiBase api, string name) [ ExtensionAttribute(), ] - public static System.Linq.IQueryable GetQueryableSource (Microsoft.Restier.Core.ApiContext context, string name, object[] arguments) + public static System.Linq.IQueryable GetQueryableSource (Microsoft.Restier.Core.ApiBase api, string name, object[] arguments) [ ExtensionAttribute(), ] - public static IQueryable`1 GetQueryableSource (Microsoft.Restier.Core.ApiContext context, string name, object[] arguments) + public static IQueryable`1 GetQueryableSource (Microsoft.Restier.Core.ApiBase api, string name, object[] arguments) [ ExtensionAttribute(), ] - public static System.Linq.IQueryable GetQueryableSource (Microsoft.Restier.Core.ApiContext context, string namespaceName, string name, object[] arguments) + public static System.Linq.IQueryable GetQueryableSource (Microsoft.Restier.Core.ApiBase api, string namespaceName, string name, object[] arguments) [ ExtensionAttribute(), ] - public static IQueryable`1 GetQueryableSource (Microsoft.Restier.Core.ApiContext context, string namespaceName, string name, object[] arguments) + public static IQueryable`1 GetQueryableSource (Microsoft.Restier.Core.ApiBase api, string namespaceName, string name, object[] arguments) [ ExtensionAttribute(), ] - public static bool HasProperty (Microsoft.Restier.Core.ApiContext context, string name) + public static bool HasProperty (Microsoft.Restier.Core.ApiBase api, string name) [ AsyncStateMachineAttribute(), ExtensionAttribute(), ] - public static System.Threading.Tasks.Task`1[[Microsoft.Restier.Core.Query.QueryResult]] QueryAsync (Microsoft.Restier.Core.ApiContext context, Microsoft.Restier.Core.Query.QueryRequest request, params System.Threading.CancellationToken cancellationToken) + public static System.Threading.Tasks.Task`1[[Microsoft.Restier.Core.Query.QueryResult]] QueryAsync (Microsoft.Restier.Core.ApiBase api, Microsoft.Restier.Core.Query.QueryRequest request, params System.Threading.CancellationToken cancellationToken) [ ExtensionAttribute(), ] - public static void SetProperty (Microsoft.Restier.Core.ApiContext context, string name, object value) + public static void SetProperty (Microsoft.Restier.Core.ApiBase api, string name, object value) [ AsyncStateMachineAttribute(), ExtensionAttribute(), ] - public static System.Threading.Tasks.Task`1[[Microsoft.Restier.Core.Submit.SubmitResult]] SubmitAsync (Microsoft.Restier.Core.ApiContext context, params Microsoft.Restier.Core.Submit.ChangeSet changeSet, params System.Threading.CancellationToken cancellationToken) + public static System.Threading.Tasks.Task`1[[Microsoft.Restier.Core.Submit.SubmitResult]] SubmitAsync (Microsoft.Restier.Core.ApiBase api, params Microsoft.Restier.Core.Submit.ChangeSet changeSet, params System.Threading.CancellationToken cancellationToken) } public sealed class Microsoft.Restier.Core.DataSourceStub { @@ -167,14 +166,6 @@ public sealed class Microsoft.Restier.Core.ServiceCollectionExtensions { public static Microsoft.Extensions.DependencyInjection.IServiceCollection MakeTransient (Microsoft.Extensions.DependencyInjection.IServiceCollection services) } -public class Microsoft.Restier.Core.ApiContext : IDisposable { - public ApiContext (System.IServiceProvider provider) - - bool IsDisposed { [CompilerGeneratedAttribute(),]public get; } - - public virtual void Dispose () -} - public class Microsoft.Restier.Core.InvocationContext { public InvocationContext (System.IServiceProvider provider) @@ -221,8 +212,8 @@ public interface Microsoft.Restier.Core.Model.IModelBuilder { } public interface Microsoft.Restier.Core.Model.IModelMapper { - bool TryGetRelevantType (Microsoft.Restier.Core.ApiContext context, string name, out System.Type& relevantType) - bool TryGetRelevantType (Microsoft.Restier.Core.ApiContext context, string namespaceName, string name, out System.Type& relevantType) + bool TryGetRelevantType (Microsoft.Restier.Core.ApiBase apiBase, string name, out System.Type& relevantType) + bool TryGetRelevantType (Microsoft.Restier.Core.ApiBase apiBase, string namespaceName, string name, out System.Type& relevantType) } public class Microsoft.Restier.Core.Model.ModelContext : Microsoft.Restier.Core.InvocationContext { diff --git a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind.Tests/QueryTests.cs b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind.Tests/QueryTests.cs index 5901f864..6415fb8e 100644 --- a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind.Tests/QueryTests.cs +++ b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind.Tests/QueryTests.cs @@ -25,7 +25,7 @@ public async Task TestTakeIncludeTotalCount() { WebApiConfig.RegisterNorthwind(config, server); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/test"); request.SetConfiguration(config); - var api = request.CreateRequestContainer("NorthwindApi").GetService(); + var api = request.CreateRequestContainer("NorthwindApi").GetService(); QueryResult result = await api.QueryAsync( new QueryRequest(api.GetQueryableSource("Orders").OrderBy(o => o.OrderDate).Take(10))); @@ -45,7 +45,7 @@ public async Task TestSkipIncludeTotalCount() WebApiConfig.RegisterNorthwind(config, server); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/test"); request.SetConfiguration(config); - var api = request.CreateRequestContainer("NorthwindApi").GetService(); + var api = request.CreateRequestContainer("NorthwindApi").GetService(); QueryResult result = await api.QueryAsync( new QueryRequest(api.GetQueryableSource("Orders").OrderBy(o => o.OrderDate).Skip(10))); @@ -65,7 +65,7 @@ public async Task TestSkipTakeIncludeTotalCount() WebApiConfig.RegisterNorthwind(config, server); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/test"); request.SetConfiguration(config); - var api = request.CreateRequestContainer("NorthwindApi").GetService(); + var api = request.CreateRequestContainer("NorthwindApi").GetService(); QueryResult result = await api.QueryAsync( new QueryRequest(api.GetQueryableSource("Orders").OrderBy(o => o.OrderDate).Skip(10).Take(25))); @@ -89,7 +89,7 @@ public async Task TestTakeNotStrippedIncludeTotalCount() WebApiConfig.RegisterNorthwind(config, server); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/test"); request.SetConfiguration(config); - var api = request.CreateRequestContainer("NorthwindApi").GetService(); + var api = request.CreateRequestContainer("NorthwindApi").GetService(); QueryResult result = await api.QueryAsync( new QueryRequest(api.GetQueryableSource("Orders").Take(10).OrderBy(o => o.OrderDate))); diff --git a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind.Tests/SaveTests.cs b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind.Tests/SaveTests.cs index 98306a45..0c5521e1 100644 --- a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind.Tests/SaveTests.cs +++ b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind.Tests/SaveTests.cs @@ -59,7 +59,7 @@ public async Task TestEntityFilterReturnsTask() { var container = new RestierContainerBuilder(typeof(TestEntityFilterReturnsTaskApi)); var provider = container.BuildContainer(); - var api = provider.GetService(); + var api = provider.GetService(); DataModificationItem createCustomer = new DataModificationItem( "Customers", diff --git a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind/Models/NorthwindApi.cs b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind/Models/NorthwindApi.cs index 4a2b6eca..e6a0b2b3 100644 --- a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind/Models/NorthwindApi.cs +++ b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Northwind/Models/NorthwindApi.cs @@ -27,7 +27,7 @@ public IQueryable ExpensiveProducts { get { - return this.Context.GetQueryableSource("Products") + return this.GetQueryableSource("Products") .Where(c => c.UnitPrice > 50); } } @@ -37,7 +37,7 @@ public IQueryable CurrentOrders { get { - return this.Context.GetQueryableSource("Orders") + return this.GetQueryableSource("Orders") .Where(o => o.ShippedDate == null); } } diff --git a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Trippin/Api/TrippinApi.cs b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Trippin/Api/TrippinApi.cs index 8007dfa7..a44f1841 100644 --- a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Trippin/Api/TrippinApi.cs +++ b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Trippin/Api/TrippinApi.cs @@ -52,7 +52,7 @@ public IQueryable Flights1 [Resource] public IQueryable Flights2 { - get { return this.Context.GetQueryableSource("Flights"); } + get { return this.GetQueryableSource("Flights"); } } [Resource] @@ -75,7 +75,7 @@ public IQueryable PeopleWithAge1 { get { - return this.Context.GetQueryableSource("People").Select(p => new PersonWithAge + return this.GetQueryableSource("People").Select(p => new PersonWithAge { Id = p.PersonId, UserName = p.UserName, diff --git a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.TrippinInMemory/Api/TrippinApi.cs b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.TrippinInMemory/Api/TrippinApi.cs index 322cd71b..21796a0c 100644 --- a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.TrippinInMemory/Api/TrippinApi.cs +++ b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.TrippinInMemory/Api/TrippinApi.cs @@ -26,7 +26,7 @@ public class TrippinApi : ApiBase { private IDataStoreManager DataStoreManager { - get { return base.Context.GetApiService>(); } + get { return this.GetApiService>(); } } private string Key diff --git a/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Properties/Resources.resx b/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Properties/Resources.resx index 5d0dd95e..02e29913 100644 --- a/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Properties/Resources.resx +++ b/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Properties/Resources.resx @@ -118,6 +118,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Unable to find DataStoreManager, please add singleton of type {0} to api services collection firstly. + Unable to find DataStoreManager, please add singleton of type {0} to apiBase services collection firstly. \ No newline at end of file