Skip to content

Commit

Permalink
cosmetic code changes (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
acn-sbuad authored Oct 25, 2023
1 parent 19dc5df commit 3d3829f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@ public static class ServiceCollectionExtensions
/// <param name="config">the configuration collection</param>
public static void AddCoreServices(this IServiceCollection services, IConfiguration config)
{
KafkaSettings? kafkaSettings = config.GetSection("KafkaSettings").Get<KafkaSettings>();
_ = config.GetSection("KafkaSettings")
.Get<KafkaSettings>()
?? throw new ArgumentNullException(nameof(config), "Required KafkaSettings is missing from application configuration");

if (kafkaSettings == null)
{
throw new ArgumentNullException(nameof(config), "Required KafkaSettings is missing from application configuration");
}

NotificationOrderConfig? settings = config.GetSection("NotificationOrderConfig").Get<NotificationOrderConfig>();

if (settings == null)
{
throw new ArgumentNullException(nameof(config), "Required NotificationOrderConfig is missing from application configuration");
}
_ = config.GetSection("NotificationOrderConfig")
.Get<NotificationOrderConfig>()
?? throw new ArgumentNullException(nameof(config), "Required NotificationOrderConfig is missing from application configuration");

services
.AddSingleton<IGuidService, GuidService>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ public static class ServiceCollectionExtensions
/// <param name="config">the configuration collection</param>
public static void AddKafkaServices(this IServiceCollection services, IConfiguration config)
{
KafkaSettings? kafkaSettings = config.GetSection(nameof(KafkaSettings)).Get<KafkaSettings>();

if (kafkaSettings == null)
{
throw new ArgumentNullException(nameof(config), "Required KafkaSettings is missing from application configuration");
}
_ = config.GetSection(nameof(KafkaSettings))
.Get<KafkaSettings>()
?? throw new ArgumentNullException(nameof(config), "Required KafkaSettings is missing from application configuration");

services
.AddSingleton<IKafkaProducer, KafkaProducer>()
Expand All @@ -43,12 +40,10 @@ public static void AddKafkaServices(this IServiceCollection services, IConfigura
/// <param name="config">the configuration collection</param>
public static void AddKafkaHealthChecks(this IServiceCollection services, IConfiguration config)
{
KafkaSettings kafkaSettings = config!.GetSection(nameof(KafkaSettings)).Get<KafkaSettings>()!;

if (kafkaSettings == null)
{
throw new ArgumentNullException(nameof(config), "Required KafkaSettings is missing from application configuration");
}
KafkaSettings kafkaSettings = config!
.GetSection(nameof(KafkaSettings))
.Get<KafkaSettings>()
?? throw new ArgumentNullException(nameof(config), "Required KafkaSettings is missing from application configuration");

services.AddHealthChecks()
.AddCheck("notifications_kafka_health_check", new KafkaHealthCheck(kafkaSettings));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using Altinn.Notifications.Core.Services.Interfaces;
using Altinn.Notifications.Integrations.Configuration;

using Confluent.Kafka;

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Altinn.Notifications.Core.Models.Orders;
using Altinn.Notifications.Integrations.Configuration;
using Altinn.Notifications.Integrations.Configuration;

using Confluent.Kafka;

Expand Down Expand Up @@ -103,7 +102,7 @@ protected async Task ConsumeMessage(
_consumer.StoreOffset(consumeResult);
}

_logger.LogError(ex, "// {Class} // ConsumeOrder // An error occurred while consuming messages", GetType().Name);
_logger.LogError(ex, "// {Class} // ConsumeMessage // An error occurred while consuming messages", GetType().Name);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Altinn.Notifications.Core.Services.Interfaces;
using Altinn.Notifications.Integrations.Configuration;

using Confluent.Kafka;

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

using Npgsql;

Expand All @@ -23,12 +22,9 @@ public static class ServiceCollectionExtensions
/// <param name="config">the configuration collection</param>
public static IServiceCollection AddPostgresRepositories(this IServiceCollection services, IConfiguration config)
{
PostgreSqlSettings? settings = config.GetSection("PostgreSQLSettings").Get<PostgreSqlSettings>();

if (settings == null)
{
throw new ArgumentNullException(nameof(config), "Required PostgreSQLSettings is missing from application configuration");
}
PostgreSqlSettings? settings = config.GetSection("PostgreSQLSettings")
.Get<PostgreSqlSettings>()
?? throw new ArgumentNullException(nameof(config), "Required PostgreSQLSettings is missing from application configuration");

string connectionString = string.Format(settings.ConnectionString, settings.NotificationsDbPwd);

Expand All @@ -45,12 +41,9 @@ public static IServiceCollection AddPostgresRepositories(this IServiceCollection
/// <param name="config">the configuration collection</param>
public static void AddPostgresHealthChecks(this IServiceCollection services, IConfiguration config)
{
PostgreSqlSettings? settings = config.GetSection("PostgreSQLSettings").Get<PostgreSqlSettings>();

if (settings == null)
{
throw new ArgumentNullException(nameof(config), "Required PostgreSQLSettings is missing from application configuration");
}
PostgreSqlSettings? settings = config.GetSection("PostgreSQLSettings")
.Get<PostgreSqlSettings>()
?? throw new ArgumentNullException(nameof(config), "Required PostgreSQLSettings is missing from application configuration");

string connectionString = string.Format(settings.ConnectionString, settings.NotificationsDbPwd);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ public static class WebApplicationExtensions
/// <param name="config">the configuration collection</param>
public static void SetUpPostgreSql(this IApplicationBuilder app, bool isDevelopment, IConfiguration config)
{
PostgreSqlSettings? settings = config.GetSection("PostgreSQLSettings").Get<PostgreSqlSettings>();

if (settings == null)
{
throw new ArgumentNullException(nameof(config), "Required PostgreSQLSettings is missing from application configuration");
}
PostgreSqlSettings? settings = config.GetSection("PostgreSQLSettings")
.Get<PostgreSqlSettings>()
?? throw new ArgumentNullException(nameof(config), "Required PostgreSQLSettings is missing from application configuration");

if (settings.EnableDBConnection)
{
Expand Down

0 comments on commit 3d3829f

Please sign in to comment.