[store] other use default client factory

This commit is contained in:
Andriy
2023-07-28 23:14:36 +03:00
parent 42509dcacd
commit 2a37b27bb4
6 changed files with 15 additions and 19 deletions
+1
View File
@@ -55,6 +55,7 @@ namespace Kruzya.TelegramBot.Core
services.AddHostedService<DeleteService>();
services.AddScoped<IOptionProvider, DbOptionProvider>();
services.AddHttpClient();
// Trigger module handlers.
_core.Modules.ConfigureServices(services);
@@ -10,12 +10,10 @@ public class AnimBoobsService : AbstractNsfwService
private readonly HttpClient _httpClient;
public override StoreItem StoreItem { get; } = new("anim_boobs", "Сиськи.gif", 120, 40);
public AnimBoobsService(AllowNsfw allowNsfw) : base(allowNsfw)
public AnimBoobsService(AllowNsfw allowNsfw, IHttpClientFactory factory) : base(allowNsfw)
{
_httpClient = new HttpClient
{
BaseAddress = new Uri("https://westdev.me/_boobs/")
};
_httpClient = factory.CreateClient();
_httpClient.BaseAddress = new Uri("https://westdev.me/_boobs/");
}
public override async Task<RandomMedia> GetRandomMediaAsync()
@@ -9,15 +9,12 @@ public abstract class AnimalAsAService : IRandomMediaService
private readonly HttpClient _httpClient;
public abstract StoreItem StoreItem { get; }
protected AnimalAsAService(Uri baseAddress)
protected AnimalAsAService(IHttpClientFactory factory, Uri baseAddress)
{
_httpClient = new HttpClient
{
BaseAddress = baseAddress
};
_httpClient = factory.CreateClient();
_httpClient.BaseAddress = baseAddress;
}
public async Task<RandomMedia> GetRandomMediaAsync()
{
var resp = await _httpClient.GetAsync("images/search");
@@ -5,5 +5,6 @@ namespace West.TelegramBot.ContentStore.Service;
public class CatApiService : AnimalAsAService
{
public override StoreItem StoreItem { get; } = new("cat", "Котэ", 40, 10);
public CatApiService() : base(new Uri("https://api.thecatapi.com/v1/")) {}
public CatApiService(IHttpClientFactory factory) :
base(factory, new Uri("https://api.thecatapi.com/v1/")) {}
}
@@ -5,5 +5,6 @@ namespace West.TelegramBot.ContentStore.Service;
public class DogApiService : AnimalAsAService
{
public override StoreItem StoreItem { get; } = new("dog", "Пёсель", 40, 20);
public DogApiService() : base(new Uri("https://api.thedogapi.com/v1/")) {}
public DogApiService(IHttpClientFactory factory) :
base(factory, new Uri("https://api.thedogapi.com/v1/")) {}
}
@@ -12,12 +12,10 @@ public class OBoobsService : AbstractNsfwService
private readonly HttpClient _httpClient;
public override StoreItem StoreItem { get; } = new("boobs", "Сиськи", 60, 30);
public OBoobsService(AllowNsfw allowNsfw) : base(allowNsfw)
public OBoobsService(AllowNsfw allowNsfw, IHttpClientFactory factory) : base(allowNsfw)
{
_httpClient = new HttpClient
{
BaseAddress = new Uri("http://api.oboobs.ru")
};
_httpClient = factory.CreateClient();
_httpClient.BaseAddress = new Uri("http://api.oboobs.ru");
}
public override async Task<RandomMedia> GetRandomMediaAsync()