Skip to content

Commit b807ce1

Browse files
committed
Simplify syntax
1 parent aefbeb3 commit b807ce1

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/NServiceBus.Core/Persistence/PersistenceComponent.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace NServiceBus;
66
using System.Collections.Generic;
77
using System.Linq;
88
using Features;
9+
using Persistence;
910
using Logging;
1011
using Settings;
1112

@@ -51,8 +52,8 @@ public static void ConfigurePersistence(this SettingsHolder settings)
5152

5253
static void ValidateSagaAndOutboxUseSamePersistence(this SettingsHolder settings, IReadOnlyCollection<EnabledPersistence> enabledPersistences)
5354
{
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;
55+
var sagaPersisterDefinition = enabledPersistences.FirstOrDefault(p => p.SelectedStorages.Contains<StorageType.Sagas>())?.Definition;
56+
var outboxPersisterDefinition = enabledPersistences.FirstOrDefault(p => p.SelectedStorages.Contains<StorageType.Outbox>())?.Definition;
5657
var bothFeaturesEnabled = settings.IsFeatureEnabled(typeof(Features.Sagas)) && settings.IsFeatureEnabled(typeof(Features.Outbox));
5758

5859
if (sagaPersisterDefinition != null
@@ -68,7 +69,7 @@ internal static bool HasSupportFor<T>(this IReadOnlySettings settings) where T :
6869
{
6970
_ = settings.TryGet(out IReadOnlyCollection<StorageType> supportedStorages);
7071

71-
return supportedStorages?.Contains(StorageType.Get<T>()) ?? false;
72+
return supportedStorages.Contains<T>();
7273
}
7374

7475
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.Persistence;
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)