Fix API service injection
This commit is contained in:
parent
1604500f2a
commit
5f79aaf960
@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using App.Metrics;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -28,6 +29,8 @@ namespace PluralKit.API
|
||||
.AddTransient<MemberStore>()
|
||||
.AddTransient<SwitchStore>()
|
||||
.AddTransient<MessageStore>()
|
||||
|
||||
.AddSingleton(svc => InitUtils.InitMetrics(svc.GetRequiredService<CoreConfig>(), "API"))
|
||||
|
||||
.AddScoped<TokenAuthService>()
|
||||
|
||||
|
@ -115,14 +115,7 @@ namespace PluralKit.Bot
|
||||
.AddTransient<MessageStore>()
|
||||
.AddTransient<SwitchStore>()
|
||||
|
||||
.AddSingleton<IMetrics>(svc =>
|
||||
{
|
||||
var cfg = svc.GetRequiredService<CoreConfig>();
|
||||
var builder = AppMetrics.CreateDefaultBuilder();
|
||||
if (cfg.InfluxUrl != null && cfg.InfluxDb != null)
|
||||
builder.Report.ToInfluxDb(cfg.InfluxUrl, cfg.InfluxDb);
|
||||
return builder.Build();
|
||||
})
|
||||
.AddSingleton(svc => InitUtils.InitMetrics(svc.GetRequiredService<CoreConfig>()))
|
||||
.AddSingleton<PeriodicStatCollector>()
|
||||
|
||||
.AddScoped(_ => new Sentry.Scope(null))
|
||||
|
@ -323,6 +323,16 @@ namespace PluralKit
|
||||
.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)
|
||||
|
Loading…
Reference in New Issue
Block a user