-
Notifications
You must be signed in to change notification settings - Fork 1
/
QuoteService.cs
75 lines (66 loc) · 2.35 KB
/
QuoteService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Net.Http;
namespace JollyQuotes
{
/// <inheritdoc cref="IQuoteService"/>
public abstract class QuoteService : IQuoteService, IDisposable
{
/// <summary>
/// <see cref="IResourceResolver"/> that is used to access requested resources.
/// </summary>
public IResourceResolver Resolver { get; }
/// <summary>
/// Determines whether the current instance has been already disposed.
/// </summary>
protected bool Disposed { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="QuoteService"/> class with a <paramref name="client"/> as the target <see cref="IResourceResolver"/> specified.
/// </summary>
/// <param name="client"><see cref="HttpClient"/> that will be used as the target <see cref="Resolver"/>.</param>
/// <exception cref="ArgumentNullException"><paramref name="client"/> is <see langword="null"/>.</exception>
protected QuoteService(HttpClient client)
{
if (client is null)
{
throw Error.Null(nameof(client));
}
Resolver = new HttpResolver(client);
}
/// <summary>
/// Initializes a new instance of the <see cref="QuoteService"/> class with an underlaying <paramref name="resolver"/> specified.
/// </summary>
/// <param name="resolver"><see cref="IResourceResolver"/> that is used to access requested <c>kanye.rest</c> resources.</param>
/// <exception cref="ArgumentNullException"><paramref name="resolver"/> is <see langword="null"/>.</exception>
protected QuoteService(IResourceResolver resolver)
{
if (resolver is null)
{
throw Error.Null(nameof(resolver));
}
Resolver = resolver;
}
/// <summary>
/// Releases the unmanaged resources used by the <see cref="QuoteService"/> and optionally disposes of the managed resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Releases the unmanaged resources used by the <see cref="QuoteService"/> and optionally disposes of the managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources;<see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (!Disposed)
{
if (disposing && Resolver is IDisposable d)
{
d.Dispose();
}
Disposed = true;
}
}
}
}