mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
* [wip] bridge python and c# and bring in rank torrent name * Container restores package now Includes two dev scripts to install the python packages locally for debugging purposes. * Introduce slightly turned title matching scoring, by making it length aware this should help with sequels such as Terminator 2, vs Terminator etc * Version bump Also fixes postgres healthcheck so that it utilises the user from the stack.env file
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
namespace SharedContracts.Extensions;
|
|
|
|
public static class ConfigurationExtensions
|
|
{
|
|
private const string ConfigurationFolder = "Configuration";
|
|
private const string LoggingConfig = "logging.json";
|
|
|
|
public static IConfigurationBuilder AddServiceConfiguration(this IConfigurationBuilder builder)
|
|
{
|
|
builder.SetBasePath(Path.Combine(AppContext.BaseDirectory, ConfigurationFolder));
|
|
|
|
builder.AddJsonFile(LoggingConfig, false, true);
|
|
|
|
builder.AddEnvironmentVariables();
|
|
|
|
return builder;
|
|
}
|
|
|
|
public static TConfiguration LoadConfigurationFromConfig<TConfiguration>(this IServiceCollection services, IConfiguration configuration, string sectionName)
|
|
where TConfiguration : class
|
|
{
|
|
var instance = configuration.GetSection(sectionName).Get<TConfiguration>();
|
|
|
|
ArgumentNullException.ThrowIfNull(instance, nameof(instance));
|
|
|
|
services.TryAddSingleton(instance);
|
|
|
|
return instance;
|
|
}
|
|
|
|
public static TConfiguration LoadConfigurationFromEnv<TConfiguration>(this IServiceCollection services)
|
|
where TConfiguration : class
|
|
{
|
|
var instance = Activator.CreateInstance<TConfiguration>();
|
|
|
|
ArgumentNullException.ThrowIfNull(instance, nameof(instance));
|
|
|
|
services.TryAddSingleton(instance);
|
|
|
|
return instance;
|
|
}
|
|
}
|