Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Get Query validator as ODataQueryContext extension methods #795

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/Microsoft.AspNetCore.OData/Microsoft.AspNetCore.OData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9831,6 +9831,69 @@
<param name="context">The query context.</param>
<returns>The built <see cref="T:Microsoft.OData.ModelBuilder.IAssemblyResolver"/>.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.ODataQueryContextExtensions.GetODataQueryValidator(Microsoft.AspNetCore.OData.Query.ODataQueryContext)">
<summary>
Gets the <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.IODataQueryValidator"/>.
</summary>
<param name="context">The query context.</param>
<returns>The built <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.IODataQueryValidator"/>.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.ODataQueryContextExtensions.GetComputeQueryValidator(Microsoft.AspNetCore.OData.Query.ODataQueryContext)">
<summary>
Gets the <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.IComputeQueryValidator"/>.
</summary>
<param name="context">The query context.</param>
<returns>The built <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.IComputeQueryValidator"/>.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.ODataQueryContextExtensions.GetCountQueryValidator(Microsoft.AspNetCore.OData.Query.ODataQueryContext)">
<summary>
Gets the <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.ICountQueryValidator"/>.
</summary>
<param name="context">The query context.</param>
<returns>The built <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.ICountQueryValidator"/>.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.ODataQueryContextExtensions.GetFilterQueryValidator(Microsoft.AspNetCore.OData.Query.ODataQueryContext)">
<summary>
Gets the <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.IFilterQueryValidator"/>.
</summary>
<param name="context">The query context.</param>
<returns>The built <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.IFilterQueryValidator"/>.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.ODataQueryContextExtensions.GetOrderByQueryValidator(Microsoft.AspNetCore.OData.Query.ODataQueryContext)">
<summary>
Gets the <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.IOrderByQueryValidator"/>.
</summary>
<param name="context">The query context.</param>
<returns>The built <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.IOrderByQueryValidator"/>.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.ODataQueryContextExtensions.GetSkipQueryValidator(Microsoft.AspNetCore.OData.Query.ODataQueryContext)">
<summary>
Gets the <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.ISkipQueryValidator"/>.
</summary>
<param name="context">The query context.</param>
<returns>The built <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.ISkipQueryValidator"/>.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.ODataQueryContextExtensions.GetSkipTokenQueryValidator(Microsoft.AspNetCore.OData.Query.ODataQueryContext)">
<summary>
Gets the <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.ISkipTokenQueryValidator"/>.
</summary>
<param name="context">The query context.</param>
<returns>The built <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.ISkipTokenQueryValidator"/>.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.ODataQueryContextExtensions.GetTopQueryValidator(Microsoft.AspNetCore.OData.Query.ODataQueryContext)">
<summary>
Gets the <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.ITopQueryValidator"/>.
</summary>
<param name="context">The query context.</param>
<returns>The built <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.ITopQueryValidator"/>.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.ODataQueryContextExtensions.GetSelectExpandQueryValidator(Microsoft.AspNetCore.OData.Query.ODataQueryContext)">
<summary>
Gets the <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.ISelectExpandQueryValidator"/>.
</summary>
<param name="context">The query context.</param>
<returns>The built <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.ISelectExpandQueryValidator"/>.</returns>
</member>
<member name="T:Microsoft.AspNetCore.OData.Query.ODataQueryOptions">
<summary>
This defines a composite OData query options that can be used to perform query composition.
Expand Down
100 changes: 100 additions & 0 deletions src/Microsoft.AspNetCore.OData/Query/ODataQueryContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using Microsoft.AspNetCore.OData.Abstracts;
using Microsoft.AspNetCore.OData.Query.Expressions;
using Microsoft.AspNetCore.OData.Query.Validator;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OData.ModelBuilder;

Expand Down Expand Up @@ -136,5 +137,104 @@ public static IAssemblyResolver GetAssemblyResolver(this ODataQueryContext conte

return resolver ?? AssemblyResolverHelper.Default;
}

/// <summary>
/// Gets the <see cref="IODataQueryValidator"/>.
/// </summary>
/// <param name="context">The query context.</param>
/// <returns>The built <see cref="IODataQueryValidator"/>.</returns>
public static IODataQueryValidator GetODataQueryValidator(this ODataQueryContext context)
{
return context?.RequestContainer?.GetService<IODataQueryValidator>()
?? new ODataQueryValidator();
}

/// <summary>
/// Gets the <see cref="IComputeQueryValidator"/>.
/// </summary>
/// <param name="context">The query context.</param>
/// <returns>The built <see cref="IComputeQueryValidator"/>.</returns>
public static IComputeQueryValidator GetComputeQueryValidator(this ODataQueryContext context)
{
return context?.RequestContainer?.GetService<IComputeQueryValidator>()
?? new ComputeQueryValidator();
}

/// <summary>
/// Gets the <see cref="ICountQueryValidator"/>.
/// </summary>
/// <param name="context">The query context.</param>
/// <returns>The built <see cref="ICountQueryValidator"/>.</returns>
public static ICountQueryValidator GetCountQueryValidator(this ODataQueryContext context)
{
return context?.RequestContainer?.GetService<ICountQueryValidator>()
?? new CountQueryValidator();
}

/// <summary>
/// Gets the <see cref="IFilterQueryValidator"/>.
/// </summary>
/// <param name="context">The query context.</param>
/// <returns>The built <see cref="IFilterQueryValidator"/>.</returns>
public static IFilterQueryValidator GetFilterQueryValidator(this ODataQueryContext context)
{
return context?.RequestContainer?.GetService<IFilterQueryValidator>()
?? new FilterQueryValidator();
}

/// <summary>
/// Gets the <see cref="IOrderByQueryValidator"/>.
/// </summary>
/// <param name="context">The query context.</param>
/// <returns>The built <see cref="IOrderByQueryValidator"/>.</returns>
public static IOrderByQueryValidator GetOrderByQueryValidator(this ODataQueryContext context)
{
return context?.RequestContainer?.GetService<IOrderByQueryValidator>()
?? new OrderByQueryValidator();
}

/// <summary>
/// Gets the <see cref="ISkipQueryValidator"/>.
/// </summary>
/// <param name="context">The query context.</param>
/// <returns>The built <see cref="ISkipQueryValidator"/>.</returns>
public static ISkipQueryValidator GetSkipQueryValidator(this ODataQueryContext context)
{
return context?.RequestContainer?.GetService<ISkipQueryValidator>()
?? new SkipQueryValidator();
}

/// <summary>
/// Gets the <see cref="ISkipTokenQueryValidator"/>.
/// </summary>
/// <param name="context">The query context.</param>
/// <returns>The built <see cref="ISkipTokenQueryValidator"/>.</returns>
public static ISkipTokenQueryValidator GetSkipTokenQueryValidator(this ODataQueryContext context)
{
return context?.RequestContainer?.GetService<ISkipTokenQueryValidator>()
?? new SkipTokenQueryValidator();
}

/// <summary>
/// Gets the <see cref="ITopQueryValidator"/>.
/// </summary>
/// <param name="context">The query context.</param>
/// <returns>The built <see cref="ITopQueryValidator"/>.</returns>
public static ITopQueryValidator GetTopQueryValidator(this ODataQueryContext context)
{
return context?.RequestContainer?.GetService<ITopQueryValidator>()
?? new TopQueryValidator();
}

/// <summary>
/// Gets the <see cref="ISelectExpandQueryValidator"/>.
/// </summary>
/// <param name="context">The query context.</param>
/// <returns>The built <see cref="ISelectExpandQueryValidator"/>.</returns>
public static ISelectExpandQueryValidator GetSelectExpandQueryValidator(this ODataQueryContext context)
{
return context?.RequestContainer?.GetService<ISelectExpandQueryValidator>()
?? new SelectExpandQueryValidator();
}
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.AspNetCore.OData/Query/ODataQueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ private void Initialize(ODataQueryContext context)

BuildQueryOptions(normalizedQueryParameters);

Validator = ODataQueryValidator.GetODataQueryValidator(context);
Validator = context.GetODataQueryValidator();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ComputeQueryOption(string rawValue, ODataQueryContext context, ODataQuery

Context = context;
RawValue = rawValue;
Validator = ComputeQueryValidator.GetComputeQueryValidator(context);
Validator = context.GetComputeQueryValidator();
_queryOptionParser = queryOptionParser;
ResultClrType = Context.ElementClrType;
}
Expand All @@ -70,7 +70,7 @@ internal ComputeQueryOption(string rawValue, ODataQueryContext context)
Context = context;
RawValue = rawValue;

Validator = ComputeQueryValidator.GetComputeQueryValidator(context);
Validator = context.GetComputeQueryValidator();
_queryOptionParser = new ODataQueryOptionParser(
context.Model,
context.ElementType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CountQueryOption(string rawValue, ODataQueryContext context, ODataQueryOp

Context = context;
RawValue = rawValue;
Validator = CountQueryValidator.GetCountQueryValidator(context);
Validator = context.GetCountQueryValidator();
_queryOptionParser = queryOptionParser;
}

Expand All @@ -66,7 +66,7 @@ internal CountQueryOption(string rawValue, ODataQueryContext context)

Context = context;
RawValue = rawValue;
Validator = CountQueryValidator.GetCountQueryValidator(context);
Validator = context.GetCountQueryValidator();
_queryOptionParser = new ODataQueryOptionParser(
context.Model,
context.ElementType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public FilterQueryOption(string rawValue, ODataQueryContext context, ODataQueryO

Context = context;
RawValue = rawValue;
Validator = FilterQueryValidator.GetFilterQueryValidator(context);
Validator = context.GetFilterQueryValidator();
_queryOptionParser = queryOptionParser;
}

Expand All @@ -69,7 +69,7 @@ internal FilterQueryOption(string rawValue, ODataQueryContext context)

Context = context;
RawValue = rawValue;
Validator = FilterQueryValidator.GetFilterQueryValidator(context);
Validator = context.GetFilterQueryValidator();
_queryOptionParser = new ODataQueryOptionParser(
context.Model,
context.ElementType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.AspNetCore.OData.Query.Expressions;
using Microsoft.AspNetCore.OData.Query.Validator;
using Microsoft.OData;
Expand Down Expand Up @@ -53,7 +52,7 @@ public OrderByQueryOption(string rawValue, ODataQueryContext context, ODataQuery

Context = context;
RawValue = rawValue;
Validator = OrderByQueryValidator.GetOrderByQueryValidator(context);
Validator = context.GetOrderByQueryValidator();
_queryOptionParser = queryOptionParser;
}

Expand All @@ -76,7 +75,7 @@ internal OrderByQueryOption(string rawValue, ODataQueryContext context, string a

Context = context;
RawValue = rawValue;
Validator = OrderByQueryValidator.GetOrderByQueryValidator(context);
Validator = context.GetOrderByQueryValidator();
_queryOptionParser = new ODataQueryOptionParser(
context.Model,
context.ElementType,
Expand All @@ -101,7 +100,7 @@ internal OrderByQueryOption(string rawValue, ODataQueryContext context)

Context = context;
RawValue = rawValue;
Validator = OrderByQueryValidator.GetOrderByQueryValidator(context);
Validator = context.GetOrderByQueryValidator();
_queryOptionParser = new ODataQueryOptionParser(
context.Model,
context.ElementType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.AspNetCore.OData.Edm;
using Microsoft.AspNetCore.OData.Query.Expressions;
using Microsoft.AspNetCore.OData.Query.Validator;
Expand Down Expand Up @@ -66,7 +65,7 @@ public SelectExpandQueryOption(string select, string expand, ODataQueryContext c
Context = context;
RawSelect = select;
RawExpand = expand;
Validator = SelectExpandQueryValidator.GetSelectExpandQueryValidator(context);
Validator = context.GetSelectExpandQueryValidator();
_queryOptionParser = queryOptionParser;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.AspNetCore.OData/Query/Query/SkipQueryOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SkipQueryOption(string rawValue, ODataQueryContext context, ODataQueryOpt

Context = context;
RawValue = rawValue;
Validator = SkipQueryValidator.GetSkipQueryValidator(context);
Validator = context.GetSkipQueryValidator();
_queryOptionParser = queryOptionParser;
}

Expand All @@ -69,7 +69,7 @@ internal SkipQueryOption(string rawValue, ODataQueryContext context)

Context = context;
RawValue = rawValue;
Validator = SkipQueryValidator.GetSkipQueryValidator(context);
Validator = context.GetSkipQueryValidator();
_queryOptionParser = new ODataQueryOptionParser(
context.Model,
context.ElementType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public SkipTokenQueryOption(string rawValue, ODataQueryContext context)
}

RawValue = rawValue;
Validator = SkipTokenQueryValidator.GetSkipTokenQueryValidator(context);
Validator = context.GetSkipTokenQueryValidator();
Handler = context.GetSkipTokenHandler();
Context = context;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.AspNetCore.OData/Query/Query/TopQueryOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public TopQueryOption(string rawValue, ODataQueryContext context, ODataQueryOpti

Context = context;
RawValue = rawValue;
Validator = TopQueryValidator.GetTopQueryValidator(context);
Validator = context.GetTopQueryValidator();
_queryOptionParser = queryOptionParser;
}

Expand All @@ -69,7 +69,7 @@ internal TopQueryOption(string rawValue, ODataQueryContext context)

Context = context;
RawValue = rawValue;
Validator = TopQueryValidator.GetTopQueryValidator(context);
Validator = context.GetTopQueryValidator();
_queryOptionParser = new ODataQueryOptionParser(
context.Model,
context.ElementType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
// </copyright>
//------------------------------------------------------------------------------

using Microsoft.Extensions.DependencyInjection;
using Microsoft.OData;

namespace Microsoft.AspNetCore.OData.Query.Validator
{
/// <summary>
Expand Down Expand Up @@ -38,11 +35,5 @@ public virtual void Validate(ComputeQueryOption computeQueryOption, ODataValidat
// however, developer can override this method add his own rules
_ = computeQueryOption.ComputeClause;
}

internal static IComputeQueryValidator GetComputeQueryValidator(ODataQueryContext context)
{
return context?.RequestContainer?.GetService<IComputeQueryValidator>() ??
new ComputeQueryValidator();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

using System;
using Microsoft.AspNetCore.OData.Edm;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OData.Edm;
using Microsoft.OData.UriParser;

Expand Down Expand Up @@ -58,11 +57,5 @@ public virtual void Validate(CountQueryOption countQueryOption, ODataValidationS
}
}
}

internal static ICountQueryValidator GetCountQueryValidator(ODataQueryContext context)
{
return context?.RequestContainer?.GetRequiredService<ICountQueryValidator>()
?? new CountQueryValidator();
}
}
}
Loading