Skip to content

Conversation

@danielmarbach
Copy link
Contributor

@danielmarbach danielmarbach commented Oct 16, 2025

Instead of refactoring the entire persistence seam, we have tried to keep the seam as close as possible to the existing assumptions but introduced slightly more type safety. All persistence implementations are geared towards using Features (even our public documentation shows that). These refactorings further strengthen the relationship between the storage type and the features for now until we fundamentally redesign the seam.

This also gets rid of the weird triple creation of the persistence implementation that made the code difficult to understand and led to downstreams like SqlPersistence having to guard certain defaults against multiple invocations.

Another angle of this PR is to reduce the usage of EnableFeatureByDefault that was mostly only used for the persistence seam integration.

Persistence definition usages have been refactored throughout the acceptance tests and core APIs to require an explicit factory interface, streamlining how persistence definitions are registered and instantiated. This also gets rid of reflection usage when we new up persistences. It also modernizes test code by using more concise syntax and updates the API surface for persistence extension methods. These changes improve type safety, consistency, and maintainability of persistence configuration in NServiceBus.

Persistence Definition Factory Refactor

  • All custom persistence definitions now implement the new IPersistenceDefinitionFactory<T> interface, and expose a static Create() method for instantiation, replacing previous patterns. This affects files such as AcceptanceTestingPersistence.cs, test persistence definitions, and the public API for learning persistence. [1] [2] [3] [4] [5]

API and Type Signature Updates

  • The generic UsePersistence<T> and PersistenceExtensions<T> APIs now require the persistence type to implement both PersistenceDefinition and IPersistenceDefinitionFactory<T>, improving type safety.

Test Code Modernization

  • Test classes and handlers are refactored to use concise syntax, such as expression-bodied members, record-like declarations, and direct assignment in constructors. This reduces boilerplate and improves readability in acceptance tests. [1] [2] [3] [4]

Feature and Storage Registration Improvements

  • Feature setup and subscription storage registration are simplified to use direct lambda expressions and singleton registrations, further reducing code complexity in test infrastructure. [1] [2]

Minor Cleanups

  • Unused using statements and redundant code are removed across several test files for clarity. [1] [2]

These changes collectively ensure that persistence configuration is more robust, maintainable, and aligned with modern C# practices.

@danielmarbach danielmarbach force-pushed the persistence-seam branch 2 times, most recently from 4b94517 to 0a09a06 Compare October 16, 2025 16:17
@danielmarbach danielmarbach changed the title Persistence seam Strong typing improvements on the persistence seam Oct 16, 2025
@danielmarbach danielmarbach requested a review from Copilot October 16, 2025 17:11
Copilot

This comment was marked as resolved.

@danielmarbach danielmarbach self-assigned this Oct 16, 2025
@danielmarbach danielmarbach marked this pull request as ready for review October 16, 2025 17:57
@danielmarbach
Copy link
Contributor Author

Demonstration of the adoption for SQL Persistence Particular/NServiceBus.Persistence.Sql#1822

@danielmarbach
Copy link
Contributor Author

NHibernate Particular/NServiceBus.NHibernate#1327

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants