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

Refactor response handling and update project structure #131

Merged
merged 3 commits into from
Nov 7, 2024

Conversation

stevejgordon
Copy link
Collaborator

@stevejgordon stevejgordon commented Nov 6, 2024

Refactored response handling to improve clarity and consistency:

  • Renamed DefaultMimeType to DefaultContentType.
  • Removed CustomResponseBuilder parameter from RequestData constructor.
  • Updated RequestCoreAsync to use contentType instead of mimeType.
  • Added ResponseFactory property to IRequestInvoker interface.
  • Refactored DefaultResponseBuilder to implement IResponseBuilder.
  • Simplified response deserialization logic.

Updated project structure and configurations:

  • Added new project Elastic.Transport.Tests.Shared.
  • Updated solution file and project references.
  • Enabled nullable reference types in several files.
  • Removed StreamResponseTests.cs and ResponseBuilderDisposeTests.cs.
  • Added new test classes for ResponseFactory, DynamicResponseBuilder, and BytesResponseBuilder.

Enhanced error handling and documentation:

  • Removed EmptyError class.
  • Updated ApiCallDetails to use nullable reference types.
  • Improved method signatures and internal logic for consistency.
  • Added license information to several files.

Refactored response handling to improve clarity and consistency:
- Renamed `DefaultMimeType` to `DefaultContentType`.
- Removed `CustomResponseBuilder` parameter from `RequestData` constructor.
- Introduced `HttpRequestInvoker` class and refactored constructors.
- Updated `RequestCoreAsync` to use `contentType` instead of `mimeType`.
- Added `ResponseFactory` property to `IRequestInvoker` interface.
- Refactored `DefaultResponseBuilder` to implement `IResponseBuilder`.
- Simplified response deserialization logic.

Updated project structure and configurations:
- Added new project `Elastic.Transport.Tests.Shared`.
- Updated solution file and project references.
- Enabled nullable reference types in several files.
- Removed `StreamResponseTests.cs` and `ResponseBuilderDisposeTests.cs`.
- Added new test classes for `ResponseFactory`, `DynamicResponseBuilder`, and `BytesResponseBuilder`.

Enhanced error handling and documentation:
- Removed `EmptyError` class.
- Updated `ApiCallDetails` to use nullable reference types.
- Improved method signatures and internal logic for consistency.
- Added license information to several files.
A new property `ResponseContentType` has been added to the `ApiCallDetails` class. This reintroduces the original `ResponseMimeType` property marked as obsolete and serves as a temporary alias for the existing `ResponseContentType` property.
@stevejgordon stevejgordon requested a review from Mpdreamz November 7, 2024 10:42
@@ -115,16 +112,19 @@ public TransportConfiguration(
/// Expert usage: Create a new transport configuration based of a previously configured instance
public TransportConfiguration(ITransportConfiguration config)
{
#if NET8_0_OR_GREATER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Let's implement a helper function for argument validation like suggested in #120.

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    internal static void NotNull([NotNull] object? obj, [CallerArgumentExpression(nameof(obj))] string? paramName = null)
    {
#if NET
        ArgumentNullException.ThrowIfNull(obj, paramName);
#else
        if (obj is null)
        {
            throw new ArgumentNullException(paramName);
        }
#endif
    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that'll be an excellent follow-up.

/// </remarks>
internal sealed class DefaultResponseFactory(ITransportConfiguration transportConfiguration) : ResponseFactory
{
private readonly ConcurrentDictionary<Type, IResponseBuilder> _resolvedBuilders = new()
Copy link
Member

@flobernd flobernd Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The builder instances in the dictionary could be static I think - they don't seem to maintain a state (maybe the DefaultResponseFactory itself is a static singleton - in this case just ignore my comment; I did not check that).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess we could have a static Default instance of them. However, we create them once, and the factory itself is only realistically expected to be created once by whichever IRequestInvoker is used for the transport.

@stevejgordon stevejgordon merged commit 0813129 into main Nov 7, 2024
5 checks passed
@stevejgordon stevejgordon deleted the response-builder branch November 7, 2024 11:58
@flobernd flobernd added the v0.5.0 label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants