-
Notifications
You must be signed in to change notification settings - Fork 16
Refactor response handling and update project structure #131
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
Conversation
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.
tests/Elastic.Transport.IntegrationTests/Responses/SpecialisedResponseTests.cs
Outdated
Show resolved
Hide resolved
| /// Expert usage: Create a new transport configuration based of a previously configured instance | ||
| public TransportConfiguration(ITransportConfiguration config) | ||
| { | ||
| #if NET8_0_OR_GREATER |
There was a problem hiding this comment.
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
}There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
Refactored response handling to improve clarity and consistency:
DefaultMimeTypetoDefaultContentType.CustomResponseBuilderparameter fromRequestDataconstructor.RequestCoreAsyncto usecontentTypeinstead ofmimeType.ResponseFactoryproperty toIRequestInvokerinterface.DefaultResponseBuilderto implementIResponseBuilder.Updated project structure and configurations:
Elastic.Transport.Tests.Shared.StreamResponseTests.csandResponseBuilderDisposeTests.cs.ResponseFactory,DynamicResponseBuilder, andBytesResponseBuilder.Enhanced error handling and documentation:
EmptyErrorclass.ApiCallDetailsto use nullable reference types.