Skip to content

Commit

Permalink
refactor: use try register instead of doing it manually
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilherme Ferreira committed Dec 6, 2023
1 parent 4f1b5c7 commit 2fff8f6
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/KafkaFlow.Retry.MongoDb/Model/DboConfigurations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ internal static void TryAddIndexes(DbContext dbContext)
),
new CreateIndexModel<RetryQueueDbo>(
Builders<RetryQueueDbo>.IndexKeys.Ascending(x => x.QueueGroupKey),
new CreateIndexOptions{ Unique = true }
new CreateIndexOptions { Unique = true }
),
new CreateIndexModel<RetryQueueDbo>(
Builders<RetryQueueDbo>.IndexKeys.Ascending(x => x.Status)
),
new CreateIndexModel<RetryQueueDbo>(
new CreateIndexModel<RetryQueueDbo>(
Builders<RetryQueueDbo>.IndexKeys.Descending(x => x.CreationDate)
),
new CreateIndexModel<RetryQueueDbo>(
new CreateIndexModel<RetryQueueDbo>(
Builders<RetryQueueDbo>.IndexKeys.Ascending(x => x.LastExecution)
)
}
Expand All @@ -53,23 +53,17 @@ internal static void TryAddIndexes(DbContext dbContext)

internal static void TryRegisterClassMapppings()
{
if (!BsonClassMap.IsClassMapRegistered(typeof(RetryQueueDbo)))
BsonClassMap.TryRegisterClassMap<RetryQueueDbo>(cm =>
{
BsonClassMap.RegisterClassMap<RetryQueueDbo>(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<RetryQueueItemDbo>(cm =>
{
BsonClassMap.RegisterClassMap<RetryQueueItemDbo>(cm =>
{
cm.AutoMap();
cm.MapIdProperty(q => q.Id).SetIdGenerator(new GuidGenerator());
});
}
cm.AutoMap();
cm.MapIdProperty(q => q.Id).SetIdGenerator(new GuidGenerator());
});
}
}
}

0 comments on commit 2fff8f6

Please sign in to comment.