Skip to content

Commit

Permalink
move to overridable function
Browse files Browse the repository at this point in the history
  • Loading branch information
aspriddell committed Nov 27, 2021
1 parent cddbebc commit 57a7c41
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
14 changes: 5 additions & 9 deletions DragonFruit.Common.Data.Tests/Requests/FilteredRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@

namespace DragonFruit.Common.Data.Tests.Requests
{
[ExceptionFilter]
internal class FilteredRequest : ApiRequest
{
public override string Path { get; }

protected override void OnRequestExecuting(ApiClient client)
{
throw new ArgumentException();
}
}

internal class InheritedRequest : FilteredRequest
{
// this should have the exception filter applied to it as well
}

internal class ExceptionFilter : RequestFilter
{
protected override void OnRequestExecuting(ApiClient client, ApiRequest request)
{
throw new ArgumentException();
}
}
}
4 changes: 1 addition & 3 deletions DragonFruit.Common.Data/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using DragonFruit.Common.Data.Exceptions;
Expand Down Expand Up @@ -287,8 +286,7 @@ protected virtual void ValidateRequest(ApiRequest request)
}
}

// check if there is a filter assigned to the class and perform it
request.GetType().GetCustomAttribute<RequestFilter>()?.OnRequestExecuting(this, request);
request.OnRequestExecuting(this);
}

/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions DragonFruit.Common.Data/ApiRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using DragonFruit.Common.Data.Exceptions;
using DragonFruit.Common.Data.Parameters;
using DragonFruit.Common.Data.Serializers;
using DragonFruit.Common.Data.Utils;
Expand Down Expand Up @@ -99,6 +100,13 @@ internal string QueryString
/// </summary>
protected virtual IEnumerable<KeyValuePair<string, string>> AdditionalQueries { get; }

/// <summary>
/// Overridable method for specifying an action to occur before sending the request to the <see cref="HttpClient"/>
/// </summary>
protected internal virtual void OnRequestExecuting(ApiClient client)
{
}

/// <summary>
/// Create a <see cref="HttpResponseMessage"/> for this <see cref="ApiRequest"/>, which can then be modified manually or overriden by <see cref="ApiClient.SetupRequest"/>
/// </summary>
Expand Down
13 changes: 0 additions & 13 deletions DragonFruit.Common.Data/RequestFilter.cs

This file was deleted.

0 comments on commit 57a7c41

Please sign in to comment.