Skip to content

Commit 7bdc5d5

Browse files
committed
Merge pull request #254 from sharwell/SimplifyCtors
Simplify public constructors for asynchronous service providers
2 parents eba8862 + c066c97 commit 7bdc5d5

File tree

7 files changed

+64
-23
lines changed

7 files changed

+64
-23
lines changed

src/corelib/Providers/Rackspace/CloudDnsProvider.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
using net.openstack.Core.Domain;
1111
using net.openstack.Core.Providers;
1212
using net.openstack.Providers.Rackspace.Objects.Dns;
13-
using net.openstack.Providers.Rackspace.Validators;
1413
using Newtonsoft.Json.Linq;
1514
using CancellationToken = System.Threading.CancellationToken;
15+
using HttpResponseCodeValidator = net.openstack.Providers.Rackspace.Validators.HttpResponseCodeValidator;
16+
using IHttpResponseCodeValidator = net.openstack.Core.Validators.IHttpResponseCodeValidator;
1617
using JsonRestServices = JSIStudios.SimpleRESTServices.Client.Json.JsonRestServices;
17-
using Thread = System.Threading.Thread;
1818

1919
/// <summary>
2020
/// Provides an implementation of <see cref="IDnsService"/> for operating
@@ -45,9 +45,23 @@ public class CloudDnsProvider : ProviderBase<IDnsService>, IDnsService
4545
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
4646
/// <param name="internalUrl"><c>true</c> to use the endpoint's <see cref="Endpoint.InternalURL"/>; otherwise <c>false</c> to use the endpoint's <see cref="Endpoint.PublicURL"/>.</param>
4747
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created using <paramref name="defaultIdentity"/> as the default identity.</param>
48-
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
49-
public CloudDnsProvider(CloudIdentity defaultIdentity, string defaultRegion, bool internalUrl, IIdentityProvider identityProvider, IRestService restService)
50-
: base(defaultIdentity, defaultRegion, identityProvider, restService, HttpResponseCodeValidator.Default)
48+
public CloudDnsProvider(CloudIdentity defaultIdentity, string defaultRegion, bool internalUrl, IIdentityProvider identityProvider)
49+
: this(defaultIdentity, defaultRegion, internalUrl, identityProvider, null, null)
50+
{
51+
}
52+
53+
/// <summary>
54+
/// Initializes a new instance of the <see cref="CloudDnsProvider"/> class with
55+
/// the specified values.
56+
/// </summary>
57+
/// <param name="defaultIdentity">The default identity to use for calls that do not explicitly specify an identity. If this value is <c>null</c>, no default identity is available so all calls must specify an explicit identity.</param>
58+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
59+
/// <param name="internalUrl"><c>true</c> to use the endpoint's <see cref="Endpoint.InternalURL"/>; otherwise <c>false</c> to use the endpoint's <see cref="Endpoint.PublicURL"/>.</param>
60+
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created using <paramref name="defaultIdentity"/> as the default identity.</param>
61+
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing synchronous REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
62+
/// <param name="httpStatusCodeValidator">The HTTP status code validator to use for synchronous REST requests. If this value is <c>null</c>, the provider will use <see cref="HttpResponseCodeValidator.Default"/>.</param>
63+
protected CloudDnsProvider(CloudIdentity defaultIdentity, string defaultRegion, bool internalUrl, IIdentityProvider identityProvider, IRestService restService, IHttpResponseCodeValidator httpStatusCodeValidator)
64+
: base(defaultIdentity, defaultRegion, identityProvider, restService, httpStatusCodeValidator)
5165
{
5266
_internalUrl = internalUrl;
5367
}

src/corelib/Providers/Rackspace/CloudLoadBalancerProvider.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using net.openstack.Providers.Rackspace.Validators;
1717
using Newtonsoft.Json.Linq;
1818
using CancellationToken = System.Threading.CancellationToken;
19+
using IHttpResponseCodeValidator = net.openstack.Core.Validators.IHttpResponseCodeValidator;
1920
using JsonRestServices = JSIStudios.SimpleRESTServices.Client.Json.JsonRestServices;
2021

2122
/// <summary>
@@ -40,9 +41,22 @@ public class CloudLoadBalancerProvider : ProviderBase<ILoadBalancerService>, ILo
4041
/// <param name="defaultIdentity">The default identity to use for calls that do not explicitly specify an identity. If this value is <c>null</c>, no default identity is available so all calls must specify an explicit identity.</param>
4142
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
4243
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created using <paramref name="defaultIdentity"/> as the default identity.</param>
43-
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
44-
public CloudLoadBalancerProvider(CloudIdentity defaultIdentity, string defaultRegion, IIdentityProvider identityProvider, IRestService restService)
45-
: base(defaultIdentity, defaultRegion, identityProvider, restService, HttpResponseCodeValidator.Default)
44+
public CloudLoadBalancerProvider(CloudIdentity defaultIdentity, string defaultRegion, IIdentityProvider identityProvider)
45+
: base(defaultIdentity, defaultRegion, identityProvider, null, null)
46+
{
47+
}
48+
49+
/// <summary>
50+
/// Initializes a new instance of the <see cref="CloudLoadBalancerProvider"/> class with
51+
/// the specified values.
52+
/// </summary>
53+
/// <param name="defaultIdentity">The default identity to use for calls that do not explicitly specify an identity. If this value is <c>null</c>, no default identity is available so all calls must specify an explicit identity.</param>
54+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
55+
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created using <paramref name="defaultIdentity"/> as the default identity.</param>
56+
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing synchronous REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
57+
/// <param name="httpStatusCodeValidator">The HTTP status code validator to use for synchronous REST requests. If this value is <c>null</c>, the provider will use <see cref="HttpResponseCodeValidator.Default"/>.</param>
58+
protected CloudLoadBalancerProvider(CloudIdentity defaultIdentity, string defaultRegion, IIdentityProvider identityProvider, IRestService restService, IHttpResponseCodeValidator httpStatusCodeValidator)
59+
: base(defaultIdentity, defaultRegion, identityProvider, restService, httpStatusCodeValidator)
4660
{
4761
}
4862

src/corelib/Providers/Rackspace/CloudQueuesProvider.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
using net.openstack.Core.Providers;
1515
using net.openstack.Providers.Rackspace.Objects.Queues.Request;
1616
using net.openstack.Providers.Rackspace.Objects.Queues.Response;
17-
using net.openstack.Providers.Rackspace.Validators;
1817
using Newtonsoft.Json;
1918
using Newtonsoft.Json.Linq;
19+
using HttpResponseCodeValidator = net.openstack.Providers.Rackspace.Validators.HttpResponseCodeValidator;
20+
using IHttpResponseCodeValidator = net.openstack.Core.Validators.IHttpResponseCodeValidator;
2021

2122
/// <summary>
2223
/// Provides an implementation of <see cref="IQueueingService"/> for operating
@@ -58,9 +59,24 @@ public class CloudQueuesProvider : ProviderBase<IQueueingService>, IQueueingServ
5859
/// <param name="clientId">The value of the <strong>Client-Id</strong> header to send with message requests from this service.</param>
5960
/// <param name="internalUrl"><c>true</c> to use the endpoint's <see cref="Endpoint.InternalURL"/>; otherwise <c>false</c> to use the endpoint's <see cref="Endpoint.PublicURL"/>.</param>
6061
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created using <paramref name="defaultIdentity"/> as the default identity.</param>
61-
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
62-
public CloudQueuesProvider(CloudIdentity defaultIdentity, string defaultRegion, Guid clientId, bool internalUrl, IIdentityProvider identityProvider, IRestService restService)
63-
: base(defaultIdentity, defaultRegion, identityProvider, restService, HttpResponseCodeValidator.Default)
62+
public CloudQueuesProvider(CloudIdentity defaultIdentity, string defaultRegion, Guid clientId, bool internalUrl, IIdentityProvider identityProvider)
63+
: this(defaultIdentity, defaultRegion, clientId, internalUrl, identityProvider, null, null)
64+
{
65+
}
66+
67+
/// <summary>
68+
/// Initializes a new instance of the <see cref="CloudQueuesProvider"/> class with
69+
/// the specified values.
70+
/// </summary>
71+
/// <param name="defaultIdentity">The default identity to use for calls that do not explicitly specify an identity. If this value is <c>null</c>, no default identity is available so all calls must specify an explicit identity.</param>
72+
/// <param name="defaultRegion">The default region to use for calls that do not explicitly specify a region. If this value is <c>null</c>, the default region for the user will be used; otherwise if the service uses region-specific endpoints all calls must specify an explicit region.</param>
73+
/// <param name="clientId">The value of the <strong>Client-Id</strong> header to send with message requests from this service.</param>
74+
/// <param name="internalUrl"><c>true</c> to use the endpoint's <see cref="Endpoint.InternalURL"/>; otherwise <c>false</c> to use the endpoint's <see cref="Endpoint.PublicURL"/>.</param>
75+
/// <param name="identityProvider">The identity provider to use for authenticating requests to this provider. If this value is <c>null</c>, a new instance of <see cref="CloudIdentityProvider"/> is created using <paramref name="defaultIdentity"/> as the default identity.</param>
76+
/// <param name="restService">The implementation of <see cref="IRestService"/> to use for executing synchronous REST requests. If this value is <c>null</c>, the provider will use a new instance of <see cref="JsonRestServices"/>.</param>
77+
/// <param name="httpStatusCodeValidator">The HTTP status code validator to use for synchronous REST requests. If this value is <c>null</c>, the provider will use <see cref="HttpResponseCodeValidator.Default"/>.</param>
78+
protected CloudQueuesProvider(CloudIdentity defaultIdentity, string defaultRegion, Guid clientId, bool internalUrl, IIdentityProvider identityProvider, IRestService restService, IHttpResponseCodeValidator httpStatusCodeValidator)
79+
: base(defaultIdentity, defaultRegion, identityProvider, restService, httpStatusCodeValidator)
6480
{
6581
_clientId = clientId;
6682
_internalUrl = internalUrl;

src/testing/integration/Providers/Rackspace/UserDnsTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
using System.Diagnostics;
66
using System.Linq;
77
using System.Net;
8-
using System.Net.Sockets;
98
using System.Text.RegularExpressions;
109
using System.Threading;
1110
using System.Threading.Tasks;
12-
using JSIStudios.SimpleRESTServices.Client;
1311
using Microsoft.VisualStudio.TestTools.UnitTesting;
1412
using net.openstack.Core;
1513
using net.openstack.Core.Domain;
@@ -863,7 +861,7 @@ internal static string CreateRandomDomainName()
863861

864862
internal static IDnsService CreateProvider()
865863
{
866-
CloudDnsProvider provider = new TestCloudDnsProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, false, null, null);
864+
CloudDnsProvider provider = new TestCloudDnsProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, false, null);
867865
provider.BeforeAsyncWebRequest +=
868866
(sender, e) =>
869867
{
@@ -880,8 +878,8 @@ internal static IDnsService CreateProvider()
880878

881879
private class TestCloudDnsProvider : CloudDnsProvider
882880
{
883-
public TestCloudDnsProvider(CloudIdentity defaultIdentity, string defaultRegion, bool internalUrl, IIdentityProvider identityProvider, IRestService restService)
884-
: base(defaultIdentity, defaultRegion, internalUrl, identityProvider, restService)
881+
public TestCloudDnsProvider(CloudIdentity defaultIdentity, string defaultRegion, bool internalUrl, IIdentityProvider identityProvider)
882+
: base(defaultIdentity, defaultRegion, internalUrl, identityProvider)
885883
{
886884
}
887885

src/testing/integration/Providers/Rackspace/UserLoadBalancerTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using CloudIdentity = net.openstack.Core.Domain.CloudIdentity;
2222
using IIdentityProvider = net.openstack.Core.Providers.IIdentityProvider;
2323
using Interlocked = System.Threading.Interlocked;
24-
using IRestService = JSIStudios.SimpleRESTServices.Client.IRestService;
2524
using Path = System.IO.Path;
2625
using StringBuilder = System.Text.StringBuilder;
2726

@@ -2060,7 +2059,7 @@ internal static string CreateRandomLoadBalancerName()
20602059
/// <returns>An instance of <see cref="ILoadBalancerService"/> for integration testing.</returns>
20612060
internal static ILoadBalancerService CreateProvider()
20622061
{
2063-
var provider = new TestCloudLoadBalancerProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, null, null);
2062+
var provider = new TestCloudLoadBalancerProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, null);
20642063
provider.BeforeAsyncWebRequest +=
20652064
(sender, e) =>
20662065
{
@@ -2079,8 +2078,8 @@ internal static ILoadBalancerService CreateProvider()
20792078

20802079
internal class TestCloudLoadBalancerProvider : CloudLoadBalancerProvider
20812080
{
2082-
public TestCloudLoadBalancerProvider(CloudIdentity defaultIdentity, string defaultRegion, IIdentityProvider identityProvider, IRestService restService)
2083-
: base(defaultIdentity, defaultRegion, identityProvider, restService)
2081+
public TestCloudLoadBalancerProvider(CloudIdentity defaultIdentity, string defaultRegion, IIdentityProvider identityProvider)
2082+
: base(defaultIdentity, defaultRegion, identityProvider)
20842083
{
20852084
}
20862085

src/testing/integration/Providers/Rackspace/UserQueuesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ private QueueName CreateRandomQueueName()
713713
/// <returns>An instance of <see cref="IQueueingService"/> for integration testing.</returns>
714714
private IQueueingService CreateProvider()
715715
{
716-
var provider = new CloudQueuesProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, Guid.NewGuid(), false, null, null);
716+
var provider = new CloudQueuesProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, Guid.NewGuid(), false, null);
717717
provider.BeforeAsyncWebRequest +=
718718
(sender, e) =>
719719
{

src/testing/integration/Providers/Rackspace/UserQueuesTestsSynchronous.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ private QueueName CreateRandomQueueName()
625625
/// <returns>An instance of <see cref="IQueueingService"/> for integration testing.</returns>
626626
private IQueueingService CreateProvider()
627627
{
628-
var provider = new CloudQueuesProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, Guid.NewGuid(), false, null, null);
628+
var provider = new CloudQueuesProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, Guid.NewGuid(), false, null);
629629
provider.ConnectionLimit = 80;
630630
return provider;
631631
}

0 commit comments

Comments
 (0)