Skip to content
2 changes: 1 addition & 1 deletion Activout.RestClient.Json.Test/SimpleValueObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SimpleValueObjectTest
{
private const string BaseUri = "https://example.com/api/";

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new();

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SystemTextJsonDeserializerTest
{
private const string BaseUri = "https://example.com/api/";

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new();

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DefaultDomainExceptionErrorObjectTests()
{
_mockHttp = new MockHttpMessageHandler();

_defaultMapperApiClient = Services.CreateRestClientFactory()
_defaultMapperApiClient = new RestClientFactory()
.CreateBuilder()
.WithNewtonsoftJson()
.With(_mockHttp.ToHttpClient())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public DomainExceptionErrorEnumTests()
{
_mockHttp = new MockHttpMessageHandler();

_myApiClient = Services.CreateRestClientFactory()
_myApiClient = new RestClientFactory()
.CreateBuilder()
.With(_mockHttp.ToHttpClient())
.WithNewtonsoftJson()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public DomainExceptionErrorObjectTests()
{
_mockHttp = new MockHttpMessageHandler();

_myApiClient = Services.CreateRestClientFactory()
_myApiClient = new RestClientFactory()
.CreateBuilder()
.WithNewtonsoftJson()
.With(_mockHttp.ToHttpClient())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class NewtonsoftJsonDeserializerTest
{
public NewtonsoftJsonDeserializerTest()
{
_restClientFactory = Services.CreateRestClientFactory();
_restClientFactory = new RestClientFactory();
_mockHttp = new MockHttpMessageHandler();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class RestClientTests
{
public RestClientTests(ITestOutputHelper outputHelper)
{
_restClientFactory = Services.CreateRestClientFactory();
_restClientFactory = new RestClientFactory();
_mockHttp = new MockHttpMessageHandler();
_loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SerializationOrderTest

public SerializationOrderTest()
{
_restClientFactory = Services.CreateRestClientFactory();
_restClientFactory = new RestClientFactory();
_mockHttp = new MockHttpMessageHandler();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class SimpleValueObjectTest
{
private const string BaseUri = "https://example.com/api/";

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new();

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test.Json/RestClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
private const string MovieId = "*MOVIE_ID*";
private const string ReviewId = "*REVIEW_ID*";

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new();
private readonly ILoggerFactory _loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper);

Expand Down Expand Up @@ -104,7 +104,7 @@
var reviewSvc = CreateRestClientBuilder(jsonImplementation)
.Accept("application/json")
.ContentType("application/json")
.With(new TaskConverterFactory())

Check warning on line 107 in Activout.RestClient.Test.Json/RestClientTests.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

'TaskConverterFactory' is obsolete: 'This class is obsolete and will be removed in a future version. Use TaskConverter3Factory instead.'

Check warning on line 107 in Activout.RestClient.Test.Json/RestClientTests.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

'TaskConverterFactory' is obsolete: 'This class is obsolete and will be removed in a future version. Use TaskConverter3Factory instead.'

Check warning on line 107 in Activout.RestClient.Test.Json/RestClientTests.cs

View workflow job for this annotation

GitHub Actions / build (10.0.x)

'TaskConverterFactory' is obsolete: 'This class is obsolete and will be removed in a future version. Use TaskConverter3Factory instead.'

Check warning on line 107 in Activout.RestClient.Test.Json/RestClientTests.cs

View workflow job for this annotation

GitHub Actions / build (10.0.x)

'TaskConverterFactory' is obsolete: 'This class is obsolete and will be removed in a future version. Use TaskConverter3Factory instead.'

Check warning on line 107 in Activout.RestClient.Test.Json/RestClientTests.cs

View workflow job for this annotation

GitHub Actions / build (9.0.x)

'TaskConverterFactory' is obsolete: 'This class is obsolete and will be removed in a future version. Use TaskConverter3Factory instead.'

Check warning on line 107 in Activout.RestClient.Test.Json/RestClientTests.cs

View workflow job for this annotation

GitHub Actions / build (9.0.x)

'TaskConverterFactory' is obsolete: 'This class is obsolete and will be removed in a future version. Use TaskConverter3Factory instead.'
.With(_loggerFactory.CreateLogger<RestClientTests>())
.With(_mockHttp.ToHttpClient())
.BaseUri(BaseUri)
Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test.Json/SerializationOrderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SerializationOrderTest
private const int OrderFirst = -1000;
private const int OrderLast = 1000;

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new();

[Theory]
Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test.Json/SimpleValueObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class SimpleValueObjectTest
{
private const string BaseUri = "https://example.com/api/";

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new();

[Theory]
Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test/BodyArgumentFormPostTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class BodyArgumentFormPostTest

public BodyArgumentFormPostTest()
{
_restClientFactory = Services.CreateRestClientFactory();
_restClientFactory = new RestClientFactory();
_mockHttp = new MockHttpMessageHandler();
}

Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test/CancellationTokenBodyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class CancellationTokenBodyTest

public CancellationTokenBodyTest()
{
_restClientFactory = Services.CreateRestClientFactory();
_restClientFactory = new RestClientFactory();
_mockHttp = new MockHttpMessageHandler();
}

Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test/DictionaryParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DictionaryParameterTests(ITestOutputHelper outputHelper)
{
private const string BaseUri = "https://example.com/api";

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new MockHttpMessageHandler();
private readonly ILoggerFactory _loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper);

Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test/ErrorResponseTextPlainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ErrorResponseTextPlainTest(ITestOutputHelper outputHelper)
{
private const string BaseUri = "https://example.com/api";

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new();
private readonly ILoggerFactory _loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper);

Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test/HttpResponseMessageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class HttpResponseMessageTest

public HttpResponseMessageTest()
{
_restClientFactory = Services.CreateRestClientFactory();
_restClientFactory = new RestClientFactory();
_mockHttp = new MockHttpMessageHandler();
}

Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test/HttpStatusCodeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class HttpStatusCodeTest

public HttpStatusCodeTest()
{
_restClientFactory = Services.CreateRestClientFactory();
_restClientFactory = new RestClientFactory();
_mockHttp = new MockHttpMessageHandler();
}

Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test/MultipartFormDataContentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MultipartFormDataContentTest

public MultipartFormDataContentTest(ITestOutputHelper outputHelper)
{
_restClientFactory = Services.CreateRestClientFactory();
_restClientFactory = new RestClientFactory();
_mockHttp = new MockHttpMessageHandler();
_loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper);
}
Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test/NonJsonRestClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class NonJsonRestClientTests(ITestOutputHelper outputHelper)
private const string MovieId = "*MOVIE_ID*";
private const string ReviewId = "*REVIEW_ID*";

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new MockHttpMessageHandler();
private readonly ILoggerFactory _loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper);

Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Test/NullParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class NullParameterTests(ITestOutputHelper outputHelper)
{
private const string BaseUri = "https://example.com/api";

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new MockHttpMessageHandler();
private readonly ILoggerFactory _loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper);

Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Xml.Test/ErrorResponseXmlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ErrorResponseXmlTest(ITestOutputHelper outputHelper)
{
private const string BaseUri = "https://example.com/api";

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new();
private readonly ILoggerFactory _loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper);

Expand Down
2 changes: 1 addition & 1 deletion Activout.RestClient.Xml.Test/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class XmlTests(ITestOutputHelper outputHelper)
{
private const string BaseUri = "https://example.com/xml";

private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory();
private readonly IRestClientFactory _restClientFactory = new RestClientFactory();
private readonly MockHttpMessageHandler _mockHttp = new MockHttpMessageHandler();
private readonly ILoggerFactory _loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper);

Expand Down
10 changes: 4 additions & 6 deletions Activout.RestClient/Helpers/ITaskConverterFactory.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#nullable disable
using System;

namespace Activout.RestClient.Helpers
namespace Activout.RestClient.Helpers;

public interface ITaskConverterFactory
{
public interface ITaskConverterFactory
{
ITaskConverter CreateTaskConverter(Type actualReturnType);
}
ITaskConverter? CreateTaskConverter(Type actualReturnType);
}
14 changes: 7 additions & 7 deletions Activout.RestClient/Helpers/Implementation/DuckTyping.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#nullable disable
using ImpromptuInterface;

namespace Activout.RestClient.Helpers.Implementation
namespace Activout.RestClient.Helpers.Implementation;

public class DuckTyping : IDuckTyping
{
public class DuckTyping : IDuckTyping
public static IDuckTyping Instance { get; } = new DuckTyping();

public TInterface DuckType<TInterface>(object originalDynamic) where TInterface : class
{
public TInterface DuckType<TInterface>(object originalDynamic) where TInterface : class
{
return originalDynamic.ActLike<TInterface>();
}
return originalDynamic.ActLike<TInterface>();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#nullable disable
using System;

namespace Activout.RestClient.Helpers.Implementation;

public class TaskConverter3Factory : ITaskConverterFactory
{
public ITaskConverter CreateTaskConverter(Type actualReturnType)
public static ITaskConverterFactory Instance { get; } = new TaskConverter3Factory();

public ITaskConverter? CreateTaskConverter(Type actualReturnType)
{
return actualReturnType == typeof(void) ? null :
(ITaskConverter) Activator.CreateInstance(typeof(TaskConverter3<>).MakeGenericType(actualReturnType));
return actualReturnType == typeof(void)
? null
: (ITaskConverter?)Activator.CreateInstance(typeof(TaskConverter3<>).MakeGenericType(actualReturnType));
}
}
34 changes: 15 additions & 19 deletions Activout.RestClient/Implementation/RestClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Net.Http;
using Activout.RestClient.DomainExceptions;
using Activout.RestClient.Helpers;
using Activout.RestClient.Helpers.Implementation;
using Activout.RestClient.ParamConverter;
using Activout.RestClient.ParamConverter.Implementation;
using Activout.RestClient.Serialization;
using Activout.RestClient.Serialization.Implementation;
using Microsoft.Extensions.Logging;
Expand All @@ -14,27 +16,15 @@ namespace Activout.RestClient.Implementation
{
internal class RestClientBuilder : IRestClientBuilder
{
private readonly IDuckTyping _duckTyping;
private readonly RestClientContext _context;
private readonly List<ISerializer> _serializers = SerializationManager.DefaultSerializers.ToList();
private readonly List<IDeserializer> _deserializers = SerializationManager.DefaultDeserializers.ToList();
private IDuckTyping _duckTyping = DuckTyping.Instance;

public RestClientBuilder(
IDuckTyping duckTyping,
IParamConverterManager paramConverterManager,
ITaskConverterFactory taskConverterFactory)
private readonly RestClientContext _context = new RestClientContext()
{
_duckTyping = duckTyping ?? throw new ArgumentNullException(nameof(duckTyping));

_context = new RestClientContext
{
TaskConverterFactory = taskConverterFactory ??
throw new ArgumentNullException(nameof(taskConverterFactory)),
ParamConverterManager = paramConverterManager ??
throw new ArgumentNullException(nameof(paramConverterManager))
};
}

ParamConverterManager = ParamConverterManager.Instance,
TaskConverterFactory = TaskConverter3Factory.Instance
};
private readonly List<ISerializer> _serializers = SerializationManager.DefaultSerializers.ToList();
private readonly List<IDeserializer> _deserializers = SerializationManager.DefaultDeserializers.ToList();

public IRestClientBuilder BaseUri(Uri apiUri)
{
Expand All @@ -54,6 +44,12 @@ public IRestClientBuilder Header(string name, object value)
return this;
}

public IRestClientBuilder With(IDuckTyping duckTyping)
{
_duckTyping = duckTyping;
return this;
}

public IRestClientBuilder With(ILogger logger)
{
_context.Logger = logger;
Expand Down
28 changes: 0 additions & 28 deletions Activout.RestClient/Implementation/RestClientFactory.cs

This file was deleted.

10 changes: 4 additions & 6 deletions Activout.RestClient/ParamConverter/IParamConverterManager.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#nullable disable
using System;
using System.Reflection;

namespace Activout.RestClient.ParamConverter
namespace Activout.RestClient.ParamConverter;

public interface IParamConverterManager
{
public interface IParamConverterManager
{
IParamConverter GetConverter(Type type, ParameterInfo parameterInfo);
}
IParamConverter? GetConverter(Type type, ParameterInfo parameterInfo);
}
Loading