Skip to content

Commit 2182440

Browse files
committed
Simplify syntax
1 parent aefbeb3 commit 2182440

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/NServiceBus.Core/Persistence/PersistenceComponent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public static void ConfigurePersistence(this SettingsHolder settings)
5151

5252
static void ValidateSagaAndOutboxUseSamePersistence(this SettingsHolder settings, IReadOnlyCollection<EnabledPersistence> enabledPersistences)
5353
{
54-
var sagaPersisterDefinition = enabledPersistences.FirstOrDefault(p => p.SelectedStorages.Contains(StorageType.Sagas.Instance))?.Definition;
55-
var outboxPersisterDefinition = enabledPersistences.FirstOrDefault(p => p.SelectedStorages.Contains(StorageType.Outbox.Instance))?.Definition;
54+
var sagaPersisterDefinition = enabledPersistences.FirstOrDefault(p => p.SelectedStorages.Contains<StorageType.Sagas>())?.Definition;
55+
var outboxPersisterDefinition = enabledPersistences.FirstOrDefault(p => p.SelectedStorages.Contains<StorageType.Outbox>())?.Definition;
5656
var bothFeaturesEnabled = settings.IsFeatureEnabled(typeof(Features.Sagas)) && settings.IsFeatureEnabled(typeof(Features.Outbox));
5757

5858
if (sagaPersisterDefinition != null
@@ -68,7 +68,7 @@ internal static bool HasSupportFor<T>(this IReadOnlySettings settings) where T :
6868
{
6969
_ = settings.TryGet(out IReadOnlyCollection<StorageType> supportedStorages);
7070

71-
return supportedStorages?.Contains(StorageType.Get<T>()) ?? false;
71+
return supportedStorages.Contains<T>();
7272
}
7373

7474
static readonly ILog Logger = LogManager.GetLogger(typeof(PersistenceComponent));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#nullable enable
2+
3+
namespace NServiceBus;
4+
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
8+
static class StorageTypeCollectionExtensions
9+
{
10+
extension(IReadOnlyCollection<StorageType>? storageTypes)
11+
{
12+
public bool Contains<TStorage>() where TStorage : StorageType
13+
{
14+
if (storageTypes is null)
15+
{
16+
return false;
17+
}
18+
19+
var storageType = StorageType.Get<TStorage>();
20+
return storageTypes.Contains(storageType);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)