Skip to content

Commit

Permalink
Make result get Api from DI
Browse files Browse the repository at this point in the history
  • Loading branch information
chinadragon0515 committed Aug 29, 2016
1 parent 9f4944c commit 19d3ced
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 46 deletions.
4 changes: 0 additions & 4 deletions src/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@
[assembly: SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.Batch.RestierBatchChangeSetRequestItem.#DisposeResponses(System.Collections.Generic.IEnumerable`1<System.Net.Http.HttpResponseMessage>)")]
[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", "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")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix", Scope = "type", Target = "Microsoft.Restier.Security.ApiPermission")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", Scope = "member", Target = "Microsoft.Restier.Core.Submit.ChangeSetEntry.#Type")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", Scope = "member", Target = "Microsoft.Restier.Core.Query.QueryModelReference.#Type")]
[assembly: SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "itemValue", Scope = "member", Target = "Microsoft.Restier.Core.Submit.DataModificationItem.#ApplyPredicate(System.Linq.Expressions.ParameterExpression,System.Linq.Expressions.Expression,System.Collections.Generic.KeyValuePair`2<System.String,System.Object>)")]
[assembly: SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Scope = "member", Target = "Microsoft.Restier.Providers.EntityFramework.ModelProducer.#.cctor()")]
[assembly: SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.RestierController`1.#GetQuery(System.Web.OData.Extensions.HttpRequestMessageProperties)", Justification = "Instance is disposed elsewhere")]
[assembly: SuppressMessage("Microsoft.Usage", "CA2237:MarkISerializableTypesWithSerializable", Scope = "type", Target = "Microsoft.Restier.Core.Submit.ChangeSetValidationException", Justification = "We do not intend to support serialization of this exception yet")]
[assembly: SuppressMessage("Microsoft.Usage", "CA2243:AttributeStringLiteralsShouldParseCorrectly", Justification = "AssemblyInformationalVersion could be string.")]

#region CA1004 Generic method with type parameter
[assembly: SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Scope = "member", Target = "Microsoft.Restier.Core.ApiConfiguration.#AddPublisherServices`1(System.Action`1<Microsoft.Extensions.DependencyInjection.IServiceCollection>)")]
[assembly: SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Scope = "member", Target = "Microsoft.Restier.Core.Query.IQueryExecutor.#ExecuteExpressionAsync`1(Microsoft.Restier.Core.Query.QueryContext,System.Linq.IQueryProvider,System.Linq.Expressions.Expression,System.Threading.CancellationToken)")]
[assembly: SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Scope = "member", Target = "Microsoft.Restier.Core.ServiceCollectionExtensions.#HasService`1(Microsoft.Extensions.DependencyInjection.IServiceCollection)")]
[assembly: SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Scope = "member", Target = "Microsoft.Restier.Core.ServiceCollectionExtensions.#AddService`2(Microsoft.Extensions.DependencyInjection.IServiceCollection)")]
Expand Down Expand Up @@ -110,7 +107,6 @@
[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.#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")]
Expand Down
17 changes: 8 additions & 9 deletions src/Microsoft.Restier.Publishers.OData/RestierController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,21 +428,21 @@ private HttpResponseMessage CreateQueryResponse(
{
if (this.shouldReturnCount || this.shouldWriteRawValue)
{
var rawResult = new RawResult(query, typeReference, this.Api);
var rawResult = new RawResult(query, typeReference);
singleResult = rawResult;
response = this.Request.CreateResponse(HttpStatusCode.OK, rawResult);
}
else
{
var primitiveResult = new PrimitiveResult(query, typeReference, this.Api);
var primitiveResult = new PrimitiveResult(query, typeReference);
singleResult = primitiveResult;
response = this.Request.CreateResponse(HttpStatusCode.OK, primitiveResult);
}
}

if (typeReference.IsComplex())
{
var complexResult = new ComplexResult(query, typeReference, this.Api);
var complexResult = new ComplexResult(query, typeReference);
singleResult = complexResult;
response = this.Request.CreateResponse(HttpStatusCode.OK, complexResult);
}
Expand All @@ -451,13 +451,13 @@ private HttpResponseMessage CreateQueryResponse(
{
if (this.shouldWriteRawValue)
{
var rawResult = new RawResult(query, typeReference, this.Api);
var rawResult = new RawResult(query, typeReference);
singleResult = rawResult;
response = this.Request.CreateResponse(HttpStatusCode.OK, rawResult);
}
else
{
var enumResult = new EnumResult(query, typeReference, this.Api);
var enumResult = new EnumResult(query, typeReference);
singleResult = enumResult;
response = this.Request.CreateResponse(HttpStatusCode.OK, enumResult);
}
Expand All @@ -481,11 +481,11 @@ private HttpResponseMessage CreateQueryResponse(
if (elementType.IsPrimitive() || elementType.IsEnum())
{
return this.Request.CreateResponse(
HttpStatusCode.OK, new NonResourceCollectionResult(query, typeReference, this.Api));
HttpStatusCode.OK, new NonResourceCollectionResult(query, typeReference));
}

return this.Request.CreateResponse(
HttpStatusCode.OK, new ResourceSetResult(query, typeReference, this.Api));
HttpStatusCode.OK, new ResourceSetResult(query, typeReference));
}

var entityResult = query.SingleOrDefault();
Expand Down Expand Up @@ -640,12 +640,11 @@ private Task<IQueryable> ExecuteOperationAsync(
CancellationToken cancellationToken)
{
var executor = Api.GetApiService<IOperationExecutor>();
var implementInstance = Api.GetApiService<ApiBase>();

var context = new OperationContext(
getParaValueFunc,
operationName,
implementInstance,
Api,
isFunction,
bindingParameterValue,
Request.GetRequestContainer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ internal abstract class BaseCollectionResult : BaseResult
/// </summary>
/// <param name="query">The query that returns a collection of objects.</param>
/// <param name="edmType">The EDM type reference of the objects.</param>
/// <param name="api">The api instance where the action is executed.</param>
protected BaseCollectionResult(IQueryable query, IEdmTypeReference edmType, ApiBase api)
: base(edmType, api)
protected BaseCollectionResult(IQueryable query, IEdmTypeReference edmType)
: base(edmType)
{
Ensure.NotNull(query, "query");

Expand Down
10 changes: 1 addition & 9 deletions src/Microsoft.Restier.Publishers.OData/Results/BaseResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ internal abstract class BaseResult
/// Initializes a new instance of the <see cref="BaseResult" /> class.
/// </summary>
/// <param name="edmType">The EDM type reference of the OData result.</param>
/// <param name="api">The api instance where the action is executed.</param>
protected BaseResult(IEdmTypeReference edmType, ApiBase api)
protected BaseResult(IEdmTypeReference edmType)
{
Ensure.NotNull(edmType, "edmType");
Ensure.NotNull(api, "api");

this.edmType = edmType;
this.Api = api;
}

/// <summary>
Expand All @@ -38,10 +35,5 @@ public IEdmTypeReference EdmType
return this.edmType;
}
}

/// <summary>
/// Gets the context where the action is executed.
/// </summary>
public ApiBase Api { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ internal abstract class BaseSingleResult : BaseResult
/// </summary>
/// <param name="query">The query that returns an object.</param>
/// <param name="edmType">The EDM type reference of the object.</param>
/// <param name="api">The api instance where the action is executed.</param>
protected BaseSingleResult(IQueryable query, IEdmTypeReference edmType, ApiBase api)
: base(edmType, api)
protected BaseSingleResult(IQueryable query, IEdmTypeReference edmType)
: base(edmType)
{
Ensure.NotNull(query, "query");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ internal class ComplexResult : BaseSingleResult
/// </summary>
/// <param name="query">The query that returns a complex value.</param>
/// <param name="edmType">The EDM type reference of the complex value.</param>
/// <param name="api">The api instance where the action is executed.</param>
public ComplexResult(IQueryable query, IEdmTypeReference edmType, ApiBase api)
: base(query, edmType, api)
public ComplexResult(IQueryable query, IEdmTypeReference edmType)
: base(query, edmType)
{
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/Microsoft.Restier.Publishers.OData/Results/EnumResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ internal class EnumResult : BaseSingleResult
/// </summary>
/// <param name="query">The query that returns a enum value.</param>
/// <param name="edmType">The EDM type reference of the enum value.</param>
/// <param name="api">The api instance where the action is executed.</param>
public EnumResult(IQueryable query, IEdmTypeReference edmType, ApiBase api)
: base(query, edmType, api)
public EnumResult(IQueryable query, IEdmTypeReference edmType)
: base(query, edmType)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ internal class NonResourceCollectionResult : BaseCollectionResult
/// </summary>
/// <param name="query">The query that returns a collection of non-entity or complex values.</param>
/// <param name="edmType">The EDM type reference of the values.</param>
/// <param name="api">The api instance where the action is executed.</param>
public NonResourceCollectionResult(IQueryable query, IEdmTypeReference edmType, ApiBase api)
: base(query, edmType, api)
public NonResourceCollectionResult(IQueryable query, IEdmTypeReference edmType)
: base(query, edmType)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ internal class PrimitiveResult : BaseSingleResult
/// </summary>
/// <param name="query">The query that returns a primitive value.</param>
/// <param name="edmType">The EDM type reference of the primitive value.</param>
/// <param name="api">The api instance where the action is executed.</param>
public PrimitiveResult(IQueryable query, IEdmTypeReference edmType, ApiBase api)
: base(query, edmType, api)
public PrimitiveResult(IQueryable query, IEdmTypeReference edmType)
: base(query, edmType)
{
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/Microsoft.Restier.Publishers.OData/Results/RawResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ internal class RawResult : BaseSingleResult
/// </summary>
/// <param name="query">The query that returns a primitive value.</param>
/// <param name="edmType">The EDM type reference of the primitive value.</param>
/// <param name="api">The api instance where the action is executed.</param>
public RawResult(IQueryable query, IEdmTypeReference edmType, ApiBase api)
: base(query, edmType, api)
public RawResult(IQueryable query, IEdmTypeReference edmType)
: base(query, edmType)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ internal class ResourceSetResult : BaseCollectionResult
/// </summary>
/// <param name="query">The query that returns a collection of resources.</param>
/// <param name="edmType">The EDM type reference of the entities or complex.</param>
/// <param name="api">The api instance where the action is executed.</param>
public ResourceSetResult(IQueryable query, IEdmTypeReference edmType, ApiBase api)
: base(query, edmType, api)
public ResourceSetResult(IQueryable query, IEdmTypeReference edmType)
: base(query, edmType)
{
}
}
Expand Down

0 comments on commit 19d3ced

Please sign in to comment.