diff --git a/src/.DS_Store b/src/.DS_Store index 59dd6be1..720babe6 100644 Binary files a/src/.DS_Store and b/src/.DS_Store differ diff --git a/src/Managing.Api/Program.cs b/src/Managing.Api/Program.cs index 2d6e6919..5778f695 100644 --- a/src/Managing.Api/Program.cs +++ b/src/Managing.Api/Program.cs @@ -42,33 +42,38 @@ builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnC builder.Configuration.AddEnvironmentVariables(); builder.Configuration.AddUserSecrets(); -SentrySdk.Init(options => +// Initialize Sentry conditionally based on DSN availability +var sentryDsn = builder.Configuration["Sentry:Dsn"]; +if (!string.IsNullOrWhiteSpace(sentryDsn)) { - // A Sentry Data Source Name (DSN) is required. - // See https://docs.sentry.io/concepts/key-terms/dsn-explainer/ - // You can set it in the SENTRY_DSN environment variable, or you can set it in code here. - options.Dsn = builder.Configuration["Sentry:Dsn"]; + SentrySdk.Init(options => + { + // A Sentry Data Source Name (DSN) is required. + // See https://docs.sentry.io/concepts/key-terms/dsn-explainer/ + // You can set it in the SENTRY_DSN environment variable, or you can set it in code here. + options.Dsn = sentryDsn; - // When debug is enabled, the Sentry client will emit detailed debugging information to the console. - // This might be helpful, or might interfere with the normal operation of your application. - // We enable it here for demonstration purposes when first trying Sentry. - // You shouldn't do this in your applications unless you're troubleshooting issues with Sentry. - options.Debug = false; + // When debug is enabled, the Sentry client will emit detailed debugging information to the console. + // This might be helpful, or might interfere with the normal operation of your application. + // We enable it here for demonstration purposes when first trying Sentry. + // You shouldn't do this in your applications unless you're troubleshooting issues with Sentry. + options.Debug = false; - // Adds request URL and headers, IP and name for users, etc. - options.SendDefaultPii = true; + // Adds request URL and headers, IP and name for users, etc. + options.SendDefaultPii = true; - // This option is recommended. It enables Sentry's "Release Health" feature. - options.AutoSessionTracking = true; + // This option is recommended. It enables Sentry's "Release Health" feature. + options.AutoSessionTracking = true; - // Enabling this option is recommended for client applications only. It ensures all threads use the same global scope. - options.IsGlobalModeEnabled = false; + // Enabling this option is recommended for client applications only. It ensures all threads use the same global scope. + options.IsGlobalModeEnabled = false; - // Example sample rate for your transactions: captures 10% of transactions - options.TracesSampleRate = 0.1; + // Example sample rate for your transactions: captures 10% of transactions + options.TracesSampleRate = 0.1; - options.Environment = builder.Environment.EnvironmentName; -}); + options.Environment = builder.Environment.EnvironmentName; + }); +} builder.Services.AddHealthChecks() .AddCheck("self", () => HealthCheckResult.Healthy(), ["api"]); diff --git a/src/Managing.Infrastructure.Messengers/Discord/DiscordService.cs b/src/Managing.Infrastructure.Messengers/Discord/DiscordService.cs index f49277fa..a917bcab 100644 --- a/src/Managing.Infrastructure.Messengers/Discord/DiscordService.cs +++ b/src/Managing.Infrastructure.Messengers/Discord/DiscordService.cs @@ -1,4 +1,4 @@ -using Discord; +using Discord; using Discord.Commands; using Discord.Net; using Discord.WebSocket; @@ -64,7 +64,11 @@ namespace Managing.Infrastructure.Messengers.Discord _client.Log += Log; _commandService.Log += Log; // look for classes implementing ModuleBase to load commands from - await _commandService.AddModulesAsync(GetType().Assembly, _services); + // Create a service scope to resolve scoped services during command module registration + using (var scope = _services.CreateScope()) + { + await _commandService.AddModulesAsync(GetType().Assembly, scope.ServiceProvider); + } // log in to Discord, using the provided token await _client.LoginAsync(TokenType.Bot, _settings.Token); // start bot