Migrate DI container to Autofac

This commit is contained in:
Ske
2020-01-26 01:27:45 +01:00
parent 4311cb3ad1
commit 1ea0526ef8
10 changed files with 384 additions and 292 deletions

View File

@@ -324,35 +324,7 @@ namespace PluralKit
// Add global type mapper for ProxyTag compound type in Postgres
NpgsqlConnection.GlobalTypeMapper.MapComposite<ProxyTag>("proxy_tag");
}
public static ILogger InitLogger(CoreConfig config, string component)
{
return new LoggerConfiguration()
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)
.MinimumLevel.Debug()
.WriteTo.Async(a =>
a.File(
new RenderedCompactJsonFormatter(),
(config.LogDir ?? "logs") + $"/pluralkit.{component}.log",
rollingInterval: RollingInterval.Day,
flushToDiskInterval: TimeSpan.FromSeconds(10),
restrictedToMinimumLevel: LogEventLevel.Information,
buffered: true))
.WriteTo.Async(a =>
a.Console(theme: AnsiConsoleTheme.Code, outputTemplate:"[{Timestamp:HH:mm:ss}] [{EventId}] {Level:u3} {Message:lj}{NewLine}{Exception}"))
.CreateLogger();
}
public static IMetrics InitMetrics(CoreConfig config, string onlyContext = null)
{
var builder = AppMetrics.CreateDefaultBuilder();
if (config.InfluxUrl != null && config.InfluxDb != null)
builder.Report.ToInfluxDb(config.InfluxUrl, config.InfluxDb);
if (onlyContext != null)
builder.Filter.ByIncludingOnlyContext(onlyContext);
return builder.Build();
}
public static JsonSerializerSettings BuildSerializerSettings() => new JsonSerializerSettings().BuildSerializerSettings();
public static JsonSerializerSettings BuildSerializerSettings(this JsonSerializerSettings settings)
@@ -362,18 +334,6 @@ namespace PluralKit
}
}
public class LoggerProvider
{
private CoreConfig _config;
public ILogger RootLogger { get; }
public LoggerProvider(CoreConfig config, string component)
{
_config = config;
RootLogger = InitUtils.InitLogger(_config, component);
}
}
public class UlongEncodeAsLongHandler : SqlMapper.TypeHandler<ulong>
{
public override ulong Parse(object value)
@@ -660,16 +620,6 @@ namespace PluralKit
}
}
public class EventIdProvider
{
public Guid EventId { get; }
public EventIdProvider()
{
EventId = Guid.NewGuid();
}
}
public static class ConnectionUtils
{
public static async IAsyncEnumerable<T> QueryStreamAsync<T>(this DbConnectionFactory connFactory, string sql, object param)