From 2fff8f62f1e295eeedc95776c73297daaf2441d9 Mon Sep 17 00:00:00 2001 From: Guilherme Ferreira Date: Wed, 6 Dec 2023 09:52:46 +0000 Subject: [PATCH] refactor: use try register instead of doing it manually --- .../Model/DboConfigurations.cs | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/KafkaFlow.Retry.MongoDb/Model/DboConfigurations.cs b/src/KafkaFlow.Retry.MongoDb/Model/DboConfigurations.cs index fa3a880f..1e9196f7 100644 --- a/src/KafkaFlow.Retry.MongoDb/Model/DboConfigurations.cs +++ b/src/KafkaFlow.Retry.MongoDb/Model/DboConfigurations.cs @@ -18,15 +18,15 @@ internal static void TryAddIndexes(DbContext dbContext) ), new CreateIndexModel( Builders.IndexKeys.Ascending(x => x.QueueGroupKey), - new CreateIndexOptions{ Unique = true } + new CreateIndexOptions { Unique = true } ), new CreateIndexModel( Builders.IndexKeys.Ascending(x => x.Status) ), - new CreateIndexModel( + new CreateIndexModel( Builders.IndexKeys.Descending(x => x.CreationDate) ), - new CreateIndexModel( + new CreateIndexModel( Builders.IndexKeys.Ascending(x => x.LastExecution) ) } @@ -53,23 +53,17 @@ internal static void TryAddIndexes(DbContext dbContext) internal static void TryRegisterClassMapppings() { - if (!BsonClassMap.IsClassMapRegistered(typeof(RetryQueueDbo))) + BsonClassMap.TryRegisterClassMap(cm => { - BsonClassMap.RegisterClassMap(cm => - { - cm.AutoMap(); - cm.MapIdProperty(q => q.Id).SetIdGenerator(new GuidGenerator()); - }); - } + cm.AutoMap(); + cm.MapIdProperty(q => q.Id).SetIdGenerator(new GuidGenerator()); + }); - if (!BsonClassMap.IsClassMapRegistered(typeof(RetryQueueItemDbo))) + BsonClassMap.TryRegisterClassMap(cm => { - BsonClassMap.RegisterClassMap(cm => - { - cm.AutoMap(); - cm.MapIdProperty(q => q.Id).SetIdGenerator(new GuidGenerator()); - }); - } + cm.AutoMap(); + cm.MapIdProperty(q => q.Id).SetIdGenerator(new GuidGenerator()); + }); } } } \ No newline at end of file