diff --git a/src/NServiceBus.AcceptanceTests/ApprovalFiles/When_endpoint_is_warmed_up.Make_sure_things_are_in_DI.approved.txt b/src/NServiceBus.AcceptanceTests/ApprovalFiles/When_endpoint_is_warmed_up.Make_sure_things_are_in_DI.approved.txt index 3cbe8b53b3..9e925588a5 100644 --- a/src/NServiceBus.AcceptanceTests/ApprovalFiles/When_endpoint_is_warmed_up.Make_sure_things_are_in_DI.approved.txt +++ b/src/NServiceBus.AcceptanceTests/ApprovalFiles/When_endpoint_is_warmed_up.Make_sure_things_are_in_DI.approved.txt @@ -3,13 +3,13 @@ NServiceBus.InferredMessageTypeEnricherBehavior - InstancePerCall NServiceBus.Transport.IDispatchMessages - SingleInstance NServiceBus.Unicast.MessageHandlerRegistry - SingleInstance ----------- Registrations not used by the core, can be removed in next major if downstreams have been confirmed to not use it ----------- +NServiceBus.CompletableSynchronizedStorageSessionAdapter - InstancePerUnitOfWork NServiceBus.CriticalError - SingleInstance NServiceBus.Hosting.HostInformation - SingleInstance NServiceBus.MessageInterfaces.IMessageMapper - SingleInstance NServiceBus.NoOpCanceling - SingleInstance NServiceBus.Notifications - SingleInstance NServiceBus.ObjectBuilder.IBuilder - InstancePerCall -NServiceBus.Persistence.CompletableSynchronizedStorageSession - InstancePerUnitOfWork NServiceBus.Persistence.SynchronizedStorageSession - InstancePerUnitOfWork NServiceBus.Pipeline.LogicalMessageFactory - SingleInstance NServiceBus.Settings.ReadOnlySettings - SingleInstance diff --git a/src/NServiceBus.AcceptanceTests/Core/Reliability/SynchronizedStorage/When_opening_storage_session_outside_pipeline.cs b/src/NServiceBus.AcceptanceTests/Core/Reliability/SynchronizedStorage/When_opening_storage_session_outside_pipeline.cs index f378c83af5..e86a0e5f08 100644 --- a/src/NServiceBus.AcceptanceTests/Core/Reliability/SynchronizedStorage/When_opening_storage_session_outside_pipeline.cs +++ b/src/NServiceBus.AcceptanceTests/Core/Reliability/SynchronizedStorage/When_opening_storage_session_outside_pipeline.cs @@ -63,21 +63,20 @@ protected override async Task OnStart(IMessageSession session) { using (var childBuilder = provider.CreateChildBuilder()) using (var completableSynchronizedStorageSession = - childBuilder.Build()) + childBuilder.Build()) { scenarioContext.AdaptedSessionIsNullBeforeOpening = - completableSynchronizedStorageSession.GetAdaptedSession() == null; + completableSynchronizedStorageSession.AdaptedSession == null; await completableSynchronizedStorageSession.Open(new ContextBag()); scenarioContext.AdaptedSessionNotNullAfterOpening = - completableSynchronizedStorageSession.GetAdaptedSession() != null; + completableSynchronizedStorageSession.AdaptedSession != null; var synchronizedStorage = childBuilder.Build(); scenarioContext.StorageSessionEqual = - completableSynchronizedStorageSession.GetAdaptedSession() - .Equals(synchronizedStorage); + completableSynchronizedStorageSession.AdaptedSession == synchronizedStorage; await completableSynchronizedStorageSession.CompleteAsync(); } diff --git a/src/NServiceBus.Core.Tests/ApprovalFiles/APIApprovals.ApproveNServiceBus.netframework.approved.txt b/src/NServiceBus.Core.Tests/ApprovalFiles/APIApprovals.ApproveNServiceBus.netframework.approved.txt index 605305b9d6..aaa897557d 100644 --- a/src/NServiceBus.Core.Tests/ApprovalFiles/APIApprovals.ApproveNServiceBus.netframework.approved.txt +++ b/src/NServiceBus.Core.Tests/ApprovalFiles/APIApprovals.ApproveNServiceBus.netframework.approved.txt @@ -46,6 +46,16 @@ namespace NServiceBus public static void DoNotEnforceBestPractices(this NServiceBus.Pipeline.IUnsubscribeContext context) { } public static bool IgnoredBestPractices(this NServiceBus.Extensibility.ExtendableOptions options) { } } + public sealed class CompletableSynchronizedStorageSessionAdapter : System.IDisposable + { + public CompletableSynchronizedStorageSessionAdapter(NServiceBus.Persistence.ISynchronizedStorageAdapter synchronizedStorageAdapter, NServiceBus.Persistence.ISynchronizedStorage synchronizedStorage) { } + public NServiceBus.Persistence.CompletableSynchronizedStorageSession AdaptedSession { get; } + public System.Threading.Tasks.Task CompleteAsync() { } + public void Dispose() { } + public System.Threading.Tasks.Task Open(NServiceBus.Extensibility.ContextBag contextBag) { } + public System.Threading.Tasks.Task TryOpen(NServiceBus.Outbox.OutboxTransaction transaction, NServiceBus.Extensibility.ContextBag context) { } + public System.Threading.Tasks.Task TryOpen(NServiceBus.Transport.TransportTransaction transportTransaction, NServiceBus.Extensibility.ContextBag context) { } + } public class static ConfigurationTimeoutExtensions { public static void TimeToWaitBeforeTriggeringCriticalErrorOnTimeoutOutages(this NServiceBus.EndpointConfiguration config, System.TimeSpan timeToWait) { } @@ -2040,12 +2050,8 @@ namespace NServiceBus.Persistence } public class static CompletableSynchronizedStorageSessionExtensions { - public static NServiceBus.Persistence.CompletableSynchronizedStorageSession GetAdaptedSession(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session) { } - public static System.Threading.Tasks.Task Open(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session, NServiceBus.Pipeline.IIncomingLogicalMessageContext context) { } - public static System.Threading.Tasks.Task Open(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session, NServiceBus.Outbox.OutboxTransaction outboxTransaction, NServiceBus.Transport.TransportTransaction transportTransaction, NServiceBus.Extensibility.ContextBag contextBag) { } - public static System.Threading.Tasks.Task Open(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session, NServiceBus.Extensibility.ContextBag context) { } - public static System.Threading.Tasks.Task TryOpen(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session, NServiceBus.Outbox.OutboxTransaction transaction, NServiceBus.Extensibility.ContextBag context) { } - public static System.Threading.Tasks.Task TryOpen(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session, NServiceBus.Transport.TransportTransaction transportTransaction, NServiceBus.Extensibility.ContextBag context) { } + public static System.Threading.Tasks.Task Open(this NServiceBus.CompletableSynchronizedStorageSessionAdapter sessionAdapter, NServiceBus.Pipeline.IIncomingLogicalMessageContext context) { } + public static System.Threading.Tasks.Task Open(this NServiceBus.CompletableSynchronizedStorageSessionAdapter sessionAdapter, NServiceBus.Outbox.OutboxTransaction outboxTransaction, NServiceBus.Transport.TransportTransaction transportTransaction, NServiceBus.Extensibility.ContextBag contextBag) { } } public interface ISynchronizedStorage { diff --git a/src/NServiceBus.Core.Tests/ApprovalFiles/APIApprovals.ApproveNServiceBus.netstandard.approved.txt b/src/NServiceBus.Core.Tests/ApprovalFiles/APIApprovals.ApproveNServiceBus.netstandard.approved.txt index 171a930d0a..63b2887414 100644 --- a/src/NServiceBus.Core.Tests/ApprovalFiles/APIApprovals.ApproveNServiceBus.netstandard.approved.txt +++ b/src/NServiceBus.Core.Tests/ApprovalFiles/APIApprovals.ApproveNServiceBus.netstandard.approved.txt @@ -46,6 +46,16 @@ namespace NServiceBus public static void DoNotEnforceBestPractices(this NServiceBus.Pipeline.IUnsubscribeContext context) { } public static bool IgnoredBestPractices(this NServiceBus.Extensibility.ExtendableOptions options) { } } + public sealed class CompletableSynchronizedStorageSessionAdapter : System.IDisposable + { + public CompletableSynchronizedStorageSessionAdapter(NServiceBus.Persistence.ISynchronizedStorageAdapter synchronizedStorageAdapter, NServiceBus.Persistence.ISynchronizedStorage synchronizedStorage) { } + public NServiceBus.Persistence.CompletableSynchronizedStorageSession AdaptedSession { get; } + public System.Threading.Tasks.Task CompleteAsync() { } + public void Dispose() { } + public System.Threading.Tasks.Task Open(NServiceBus.Extensibility.ContextBag contextBag) { } + public System.Threading.Tasks.Task TryOpen(NServiceBus.Outbox.OutboxTransaction transaction, NServiceBus.Extensibility.ContextBag context) { } + public System.Threading.Tasks.Task TryOpen(NServiceBus.Transport.TransportTransaction transportTransaction, NServiceBus.Extensibility.ContextBag context) { } + } public class static ConfigurationTimeoutExtensions { public static void TimeToWaitBeforeTriggeringCriticalErrorOnTimeoutOutages(this NServiceBus.EndpointConfiguration config, System.TimeSpan timeToWait) { } @@ -2042,12 +2052,8 @@ namespace NServiceBus.Persistence } public class static CompletableSynchronizedStorageSessionExtensions { - public static NServiceBus.Persistence.CompletableSynchronizedStorageSession GetAdaptedSession(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session) { } - public static System.Threading.Tasks.Task Open(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session, NServiceBus.Pipeline.IIncomingLogicalMessageContext context) { } - public static System.Threading.Tasks.Task Open(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session, NServiceBus.Outbox.OutboxTransaction outboxTransaction, NServiceBus.Transport.TransportTransaction transportTransaction, NServiceBus.Extensibility.ContextBag contextBag) { } - public static System.Threading.Tasks.Task Open(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session, NServiceBus.Extensibility.ContextBag context) { } - public static System.Threading.Tasks.Task TryOpen(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session, NServiceBus.Outbox.OutboxTransaction transaction, NServiceBus.Extensibility.ContextBag context) { } - public static System.Threading.Tasks.Task TryOpen(this NServiceBus.Persistence.CompletableSynchronizedStorageSession session, NServiceBus.Transport.TransportTransaction transportTransaction, NServiceBus.Extensibility.ContextBag context) { } + public static System.Threading.Tasks.Task Open(this NServiceBus.CompletableSynchronizedStorageSessionAdapter sessionAdapter, NServiceBus.Pipeline.IIncomingLogicalMessageContext context) { } + public static System.Threading.Tasks.Task Open(this NServiceBus.CompletableSynchronizedStorageSessionAdapter sessionAdapter, NServiceBus.Outbox.OutboxTransaction outboxTransaction, NServiceBus.Transport.TransportTransaction transportTransaction, NServiceBus.Extensibility.ContextBag contextBag) { } } public interface ISynchronizedStorage { diff --git a/src/NServiceBus.Core/Pipeline/Incoming/LoadHandlersConnector.cs b/src/NServiceBus.Core/Pipeline/Incoming/LoadHandlersConnector.cs index bd6495812e..45c141456d 100644 --- a/src/NServiceBus.Core/Pipeline/Incoming/LoadHandlersConnector.cs +++ b/src/NServiceBus.Core/Pipeline/Incoming/LoadHandlersConnector.cs @@ -17,7 +17,7 @@ public LoadHandlersConnector(MessageHandlerRegistry messageHandlerRegistry) => public override async Task Invoke(IIncomingLogicalMessageContext context, Func stage) { // registered in UnitOfWork scope, therefore can't be resolved at connector construction time - using (var storageSessionAdapter = context.Builder.Build()) + using (var storageSessionAdapter = context.Builder.Build()) { await storageSessionAdapter.Open(context).ConfigureAwait(false); @@ -38,7 +38,7 @@ public override async Task Invoke(IIncomingLogicalMessageContext context, Func(b => + hostingConfiguration.Container.ConfigureComponent(b => { var adapter = hostingConfiguration.Container.HasComponent() ? b.Build() : new NoOpSynchronizedStorageAdapter(); var syncStorage = hostingConfiguration.Container.HasComponent() ? b.Build() : new NoOpSynchronizedStorage(); diff --git a/src/NServiceBus.Core/Reliability/SynchronizedStorage/CompletableSynchronizedStorageSessionAdapter.cs b/src/NServiceBus.Core/Reliability/SynchronizedStorage/CompletableSynchronizedStorageSessionAdapter.cs index 9fe535bb82..26558a2b49 100644 --- a/src/NServiceBus.Core/Reliability/SynchronizedStorage/CompletableSynchronizedStorageSessionAdapter.cs +++ b/src/NServiceBus.Core/Reliability/SynchronizedStorage/CompletableSynchronizedStorageSessionAdapter.cs @@ -1,5 +1,6 @@ namespace NServiceBus { + using System; using System.Threading.Tasks; using Extensibility; using Janitor; @@ -7,16 +8,29 @@ namespace NServiceBus using Persistence; using Transport; + /// + /// Wraps the logic to open a via and . + /// [SkipWeaving] - sealed class CompletableSynchronizedStorageSessionAdapter : CompletableSynchronizedStorageSession + public sealed class CompletableSynchronizedStorageSessionAdapter : IDisposable { + /// + /// Creates a new instance of . + /// public CompletableSynchronizedStorageSessionAdapter(ISynchronizedStorageAdapter synchronizedStorageAdapter, ISynchronizedStorage synchronizedStorage) { this.synchronizedStorage = synchronizedStorage; this.synchronizedStorageAdapter = synchronizedStorageAdapter; } + + /// + /// Access to the once it has been opened. + /// public CompletableSynchronizedStorageSession AdaptedSession { get; private set; } + /// + /// Disposes the adapter and the underlying . + /// public void Dispose() { if (disposed) @@ -28,8 +42,14 @@ public void Dispose() disposed = true; } + /// + /// Completes the underlying . + /// public Task CompleteAsync() => AdaptedSession.CompleteAsync(); + /// + /// Tries to open a based on a given . + /// public async Task TryOpen(OutboxTransaction transaction, ContextBag context) { AdaptedSession = await synchronizedStorageAdapter.TryAdapt(transaction, context).ConfigureAwait(false); @@ -37,6 +57,9 @@ public async Task TryOpen(OutboxTransaction transaction, ContextBag contex return AdaptedSession != null; } + /// + /// Tries to open a based on a given . + /// public async Task TryOpen(TransportTransaction transportTransaction, ContextBag context) { AdaptedSession = await synchronizedStorageAdapter.TryAdapt(transportTransaction, context).ConfigureAwait(false); @@ -44,6 +67,9 @@ public async Task TryOpen(TransportTransaction transportTransaction, Conte return AdaptedSession != null; } + /// + /// Opens a via the persister that is not connected to an outbox or transport transaction. + /// public async Task Open(ContextBag contextBag) => AdaptedSession = await synchronizedStorage.OpenSession(contextBag).ConfigureAwait(false); bool disposed; diff --git a/src/NServiceBus.Core/Reliability/SynchronizedStorage/CompletableSynchronizedStorageSessionExtensions.cs b/src/NServiceBus.Core/Reliability/SynchronizedStorage/CompletableSynchronizedStorageSessionExtensions.cs index 75b7287afd..06a79cd180 100644 --- a/src/NServiceBus.Core/Reliability/SynchronizedStorage/CompletableSynchronizedStorageSessionExtensions.cs +++ b/src/NServiceBus.Core/Reliability/SynchronizedStorage/CompletableSynchronizedStorageSessionExtensions.cs @@ -14,75 +14,38 @@ public static class CompletableSynchronizedStorageSessionExtensions /// /// Opens the storage session by attempting to extract the outbox and transport transaction from the incoming logical context. /// - /// The storage session. + /// The storage session. /// The context information. - public static Task Open(this CompletableSynchronizedStorageSession session, + public static Task Open(this CompletableSynchronizedStorageSessionAdapter sessionAdapter, IIncomingLogicalMessageContext context) { var outboxTransaction = context.Extensions.Get(); var transportTransaction = context.Extensions.Get(); - return session.Open(outboxTransaction, transportTransaction, context.Extensions); + return sessionAdapter.Open(outboxTransaction, transportTransaction, context.Extensions); } /// /// Opens the storage session based on the outbox or the transport transaction. /// - /// The storage session. + /// The storage session. /// The outbox transaction. /// The transport transaction. /// The context bag. - public static async Task Open(this CompletableSynchronizedStorageSession session, + public static async Task Open(this CompletableSynchronizedStorageSessionAdapter sessionAdapter, OutboxTransaction outboxTransaction, TransportTransaction transportTransaction, ContextBag contextBag) { - if (await session.TryOpen(outboxTransaction, contextBag).ConfigureAwait(false)) + if (await sessionAdapter.TryOpen(outboxTransaction, contextBag).ConfigureAwait(false)) { return; } - if (await session.TryOpen(transportTransaction, contextBag).ConfigureAwait(false)) + if (await sessionAdapter.TryOpen(transportTransaction, contextBag).ConfigureAwait(false)) { return; } - await session.Open(contextBag).ConfigureAwait(false); + await sessionAdapter.Open(contextBag).ConfigureAwait(false); } - - /// - /// Tries to open the storage session with the provided outbox transaction. - /// - /// The storage session. - /// Outbox transaction. - /// Context. - /// true when the session was opened; otherwise false. - public static Task TryOpen(this CompletableSynchronizedStorageSession session, - OutboxTransaction transaction, ContextBag context) => - ((CompletableSynchronizedStorageSessionAdapter)session).TryOpen(transaction, context); - - /// - /// Tries to open the storage session with the provided transport transaction. - /// - /// The storage session. - /// Transport transaction. - /// Context. - /// true when the session was opened; otherwise false. - public static Task TryOpen(this CompletableSynchronizedStorageSession session, - TransportTransaction transportTransaction, ContextBag context) => - ((CompletableSynchronizedStorageSessionAdapter)session).TryOpen(transportTransaction, context); - - /// - /// Opens the storage session. - /// - /// The storage session. - /// The context information. - public static Task Open(this CompletableSynchronizedStorageSession session, ContextBag context) => - ((CompletableSynchronizedStorageSessionAdapter)session).Open(context); - - /// - /// Returns the underlying, persistence specific, storage session. - /// - /// The storage session. - public static CompletableSynchronizedStorageSession GetAdaptedSession(this CompletableSynchronizedStorageSession session) => - ((CompletableSynchronizedStorageSessionAdapter)session).AdaptedSession; } } \ No newline at end of file diff --git a/src/NServiceBus.Core/Reliability/SynchronizedStorage/SynchronizedStorage.cs b/src/NServiceBus.Core/Reliability/SynchronizedStorage/SynchronizedStorage.cs index 6edef2f50c..917656f3e9 100644 --- a/src/NServiceBus.Core/Reliability/SynchronizedStorage/SynchronizedStorage.cs +++ b/src/NServiceBus.Core/Reliability/SynchronizedStorage/SynchronizedStorage.cs @@ -17,7 +17,7 @@ internal SynchronizedStorage() protected internal override void Setup(FeatureConfigurationContext context) { context.Container.ConfigureComponent( - builder => builder.Build().GetAdaptedSession(), + builder => builder.Build().AdaptedSession, DependencyLifecycle.InstancePerUnitOfWork); } } diff --git a/src/NServiceBus.Persistence.InMemory.AcceptanceTests/ApprovalFiles/When_endpoint_is_warmed_up.Make_sure_things_are_in_DI.approved.txt b/src/NServiceBus.Persistence.InMemory.AcceptanceTests/ApprovalFiles/When_endpoint_is_warmed_up.Make_sure_things_are_in_DI.approved.txt index f0686d850c..46e1a35844 100644 --- a/src/NServiceBus.Persistence.InMemory.AcceptanceTests/ApprovalFiles/When_endpoint_is_warmed_up.Make_sure_things_are_in_DI.approved.txt +++ b/src/NServiceBus.Persistence.InMemory.AcceptanceTests/ApprovalFiles/When_endpoint_is_warmed_up.Make_sure_things_are_in_DI.approved.txt @@ -6,6 +6,7 @@ NServiceBus.Transport.IDispatchMessages - SingleInstance NServiceBus.Unicast.MessageHandlerRegistry - SingleInstance NServiceBus.Unicast.Messages.MessageMetadataRegistry - SingleInstance ----------- Registrations not used by the core, can be removed in next major if downstreams have been confirmed to not use it ----------- +NServiceBus.CompletableSynchronizedStorageSessionAdapter - InstancePerUnitOfWork NServiceBus.CriticalError - SingleInstance NServiceBus.Hosting.HostInformation - SingleInstance NServiceBus.InMemorySubscriptionStorage - SingleInstance @@ -15,7 +16,6 @@ NServiceBus.MessageInterfaces.IMessageMapper - SingleInstance NServiceBus.NoOpCanceling - SingleInstance NServiceBus.Notifications - SingleInstance NServiceBus.ObjectBuilder.IBuilder - InstancePerCall -NServiceBus.Persistence.CompletableSynchronizedStorageSession - InstancePerUnitOfWork NServiceBus.Persistence.SynchronizedStorageSession - InstancePerUnitOfWork NServiceBus.Pipeline.LogicalMessageFactory - SingleInstance NServiceBus.Settings.ReadOnlySettings - SingleInstance