Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikus1993 committed Jan 27, 2024
1 parent a88062d commit 29be1c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ namespace XboxPromotionCheckerBot.App.Infrastructure.Extensions;

public static class WebApplicationBuilderExtensions
{
private static DiscordWebhookClient CreateDiscordWebhookClient(string webhookurl)
{
ArgumentException.ThrowIfNullOrEmpty(webhookurl);
return new DiscordWebhookClient(webhookurl);
}

public static async Task<IServiceCollection> AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
{
var client = MongoDbSetup.MongoClient(configuration.GetConnectionString("Games"));

Check warning on line 27 in src/XboxPromotionCheckerBot.App/Infrastructure/Extensions/WebApplicationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'connection' in 'IMongoClient MongoDbSetup.MongoClient(string connection)'.
Expand All @@ -28,7 +34,8 @@ public static async Task<IServiceCollection> AddInfrastructure(this IServiceColl
services.AddSingleton<DiscordWebhookClient>(sp =>
{
var cfg = sp.GetRequiredService<IConfiguration>();
return new DiscordWebhookClient(cfg.GetConnectionString("DiscordWebhookUrl"));
var url = cfg.GetConnectionString("DiscordWebhookUrl");
return CreateDiscordWebhookClient(url);

Check warning on line 38 in src/XboxPromotionCheckerBot.App/Infrastructure/Extensions/WebApplicationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'webhookurl' in 'DiscordWebhookClient WebApplicationBuilderExtensions.CreateDiscordWebhookClient(string webhookurl)'.
});

services.AddScoped<IGamesFilter, GameNameFilter>(sp =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ public static class MongoDbSetup

public static IMongoDatabase GamesDb(this IMongoClient client) => client.GetDatabase("GamesNew");

public static IMongoClient MongoClient(string connection) => new MongoClient(connection);
public static IMongoClient MongoClient(string connection)
{
ArgumentException.ThrowIfNullOrEmpty(connection);
return new MongoClient(connection);
}
public static async Task Setup(this IMongoDatabase db)
{
BsonClassMap.RegisterClassMap<MongoXboxGame>(classMap =>
Expand Down
3 changes: 2 additions & 1 deletion src/XboxPromotionCheckerBot.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

var builder = CoconaApp.CreateBuilder();

builder.Configuration.AddEnvironmentVariables();
builder.Configuration.AddJsonFile("appsettings.json", optional: false);
builder.Configuration.AddUserSecrets<Program>();
builder.Configuration.AddEnvironmentVariables();
builder.Configuration.AddCommandLine(args);

builder.Services.AddCore(builder.Configuration);
await builder.Services.AddInfrastructure(builder.Configuration);
Expand Down

0 comments on commit 29be1c2

Please sign in to comment.