public static IServiceCollection AddArachneInfrastructure( this IServiceCollection services, DanbooruSettings danbooruSettings, SankakuSettings sankakuSettings) { // singleton: contains cache of loaders (ensure delays and such) services.AddSingleton <ISearchEngineProvider, SearchEngineProvider>(); // todo find all ifactory and register them services.RegisterTypedFactory <BooruSearchEngine.IFactory>().ForConcreteType <BooruSearchEngine>(); var policy = HttpPolicyExtensions.HandleTransientHttpError() .WaitAndRetryAsync(2, i => TimeSpan.FromMilliseconds(100 * Math.Pow(10, i))); services.AddHttpClient <YandereLoaderFabric>() .AddPolicyHandler(policy); services.AddHttpClient <DanbooruLoaderFabric>() .AddPolicyHandler(policy); services.AddHttpClient <SankakuLoaderFabric>() .AddPolicyHandler(policy); services.AddTransient <IBooruLoaderFabric>(provider => provider.GetRequiredService <YandereLoaderFabric>()); services.AddTransient <IBooruLoaderFabric>(provider => provider.GetRequiredService <DanbooruLoaderFabric>()); services.AddTransient <IBooruLoaderFabric>(provider => provider.GetRequiredService <SankakuLoaderFabric>()); services.AddTransient <DanbooruSettings>(x => danbooruSettings); services.AddTransient <SankakuSettings>(x => sankakuSettings); services.AddTransient <IBooruPostConverter, BooruPostConverter>(); return(services); }
public DanbooruLoaderFabric(HttpClient httpClient, DanbooruSettings settings) { _httpClient = httpClient; _settings = settings; }