|
1 | | -using ReversoAPI.Web.ContextFeature.Domain.Core.Services; |
| 1 | +using System; |
| 2 | +using ReversoAPI.Web.ConjugationFeature.Domain.Core.Services; |
| 3 | +using ReversoAPI.Web.ContextFeature.Domain.Core.Services; |
| 4 | +using ReversoAPI.Web.SynonymsFeature.Domain.Core.Services; |
2 | 5 | using ReversoAPI.Web.Shared.Domain.Interfaces.Services; |
3 | 6 | using ReversoAPI.Web.Shared.Infrastructure.Http; |
4 | 7 | using ReversoAPI.Web.Shared.Infrastructure.Http.Interfaces; |
5 | 8 | using ReversoAPI.Web.Shared.Infrastructure.Logger; |
6 | | -using ReversoAPI.Web.SynonymsFeature.Domain.Core.Services; |
7 | | -using System; |
8 | 9 |
|
9 | 10 | namespace ReversoAPI.Web |
10 | 11 | { |
11 | 12 | public class ReversoClientConfig |
12 | 13 | { |
13 | 14 | // General |
14 | | - public IHttpClient HttpClient { get; private set; } |
15 | | - public IAPIConnector APIConnector { get; private set; } |
| 15 | + private IHttpClient _httpClient; |
| 16 | + public IHttpClient HttpClient |
| 17 | + { |
| 18 | + get => _httpClient ?? new CachedHttpClient(); |
| 19 | + private set => _httpClient = value; |
| 20 | + } |
| 21 | + |
| 22 | + private IAPIConnector _apiConnector; |
| 23 | + public IAPIConnector APIConnector |
| 24 | + { |
| 25 | + get => _apiConnector ?? new APIConnector(new CachedHttpClient()); |
| 26 | + private set => _apiConnector = value; |
| 27 | + } |
16 | 28 |
|
17 | | - // Let's fill up only elementary fields |
18 | | - // complex objects neither will be filled by user or will be setted by default |
19 | | - private IParser<ContextData> _contextParser; |
20 | | - public IParser<ContextData> ContextParser |
| 29 | + private IParseService<ContextData> _contextParser; |
| 30 | + public IParseService<ContextData> ContextParser |
21 | 31 | { |
22 | | - get => _contextParser ?? new ContextParserService(Logger); |
| 32 | + get => _contextParser ?? new ContextParseService(Logger); |
23 | 33 | private set => _contextParser = value; |
24 | 34 | } |
25 | | - public IParser<SynonymsData> SynonymsParser { get; private set; } |
| 35 | + |
| 36 | + private IParseService<SynonymsData> _synonymsParser; |
| 37 | + public IParseService<SynonymsData> SynonymsParser |
| 38 | + { |
| 39 | + get => _synonymsParser ?? new SynonymsParseService(Logger); |
| 40 | + private set => _synonymsParser = value; |
| 41 | + } |
| 42 | + |
| 43 | + private IParseService<ConjugationData> _conjugationParser; |
| 44 | + public IParseService<ConjugationData> ConjugationParser |
| 45 | + { |
| 46 | + get => _conjugationParser ?? new ConjugationParseService(Logger); |
| 47 | + private set => _conjugationParser = value; |
| 48 | + } |
26 | 49 |
|
27 | 50 | // Extra |
28 | 51 | public ILogger Logger { get; private set; } |
29 | 52 |
|
30 | | - private ReversoClientConfig( |
| 53 | + public ReversoClientConfig() { } |
| 54 | + |
| 55 | + public ReversoClientConfig( |
31 | 56 | IHttpClient httpClient, |
32 | 57 | IAPIConnector apiConnector, |
33 | | - IParser<ContextData> contextParser, |
34 | | - IParser<SynonymsData> synonymsParser, |
| 58 | + IParseService<ContextData> contextParser, |
| 59 | + IParseService<SynonymsData> synonymsParser, |
| 60 | + IParseService<ConjugationData> conjugationParser, |
35 | 61 | ILogger logger) |
36 | 62 | { |
37 | 63 | HttpClient = httpClient; |
38 | 64 | APIConnector = apiConnector; |
39 | 65 | ContextParser = contextParser; |
| 66 | + SynonymsParser = synonymsParser; |
| 67 | + ConjugationParser = conjugationParser; |
40 | 68 | Logger = logger; |
41 | 69 | } |
42 | 70 |
|
43 | | - ReversoClientConfig CreateDefault() |
| 71 | + public ReversoClientConfig CreateDefault() |
44 | 72 | { |
45 | 73 | var httpClient = new CachedHttpClient(); |
46 | 74 |
|
47 | 75 | return new ReversoClientConfig( |
48 | 76 | httpClient, |
49 | 77 | new APIConnector(httpClient), |
50 | | - new ContextParserService(null), |
51 | | - new SynonymsParserService(null), |
| 78 | + new ContextParseService(null), |
| 79 | + new SynonymsParseService(null), |
| 80 | + new ConjugationParseService(null), |
52 | 81 | null); |
53 | 82 | } |
54 | 83 |
|
55 | | - ReversoClientConfig WithHttpClient(IHttpClient httpClient) |
| 84 | + public ReversoClientConfig WithHttpClient(IHttpClient httpClient) |
56 | 85 | { |
57 | 86 | if(httpClient is null) throw new ArgumentNullException(nameof(httpClient)); |
58 | 87 |
|
59 | 88 | HttpClient = httpClient; |
60 | 89 | return this; |
61 | 90 | } |
62 | 91 |
|
63 | | - ReversoClientConfig WithApiConnector(IAPIConnector apiConnector) |
| 92 | + public ReversoClientConfig WithApiConnector(IAPIConnector apiConnector) |
64 | 93 | { |
65 | 94 | if (apiConnector is null) throw new ArgumentNullException(nameof(apiConnector)); |
66 | 95 |
|
67 | 96 | APIConnector = apiConnector; |
68 | 97 | return this; |
69 | 98 | } |
70 | 99 |
|
71 | | - ReversoClientConfig WithLogger(ILogger logger) |
| 100 | + public ReversoClientConfig WithContextParseService(IParseService<ContextData> contextParser) |
| 101 | + { |
| 102 | + if (contextParser is null) throw new ArgumentNullException(nameof(contextParser)); |
| 103 | + |
| 104 | + ContextParser = contextParser; |
| 105 | + return this; |
| 106 | + } |
| 107 | + |
| 108 | + public ReversoClientConfig WithSynonymsParseService(IParseService<SynonymsData> synonymsParser) |
| 109 | + { |
| 110 | + if (synonymsParser is null) throw new ArgumentNullException(nameof(synonymsParser)); |
| 111 | + |
| 112 | + SynonymsParser = synonymsParser; |
| 113 | + return this; |
| 114 | + } |
| 115 | + |
| 116 | + public ReversoClientConfig WithConjugationParseService(IParseService<ConjugationData> conjugationParser) |
| 117 | + { |
| 118 | + if (conjugationParser is null) throw new ArgumentNullException(nameof(conjugationParser)); |
| 119 | + |
| 120 | + ConjugationParser = conjugationParser; |
| 121 | + return this; |
| 122 | + } |
| 123 | + |
| 124 | + public ReversoClientConfig WithLogger(ILogger logger) |
72 | 125 | { |
73 | 126 | Logger = logger; |
74 | 127 | return this; |
|
0 commit comments