Skip to content

Commit 513f824

Browse files
Upgrade Guide: Features, Installers, IWant (#7969)
* Features in upgrade guide * Installers too * Non-upgrade-guide docs for features and installers * IWantToRunBeforeConfigurationIsFinalized * Fix link * Update nservicebus/upgrades/9to10/index.md --------- Co-authored-by: Daniel Marbach <daniel.marbach@openplace.net>
1 parent e375118 commit 513f824

File tree

7 files changed

+101
-7
lines changed

7 files changed

+101
-7
lines changed
Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
namespace Core;
1+
using NServiceBus;
2+
using NServiceBus.Features;
3+
4+
namespace Core;
25

36
using System.Threading;
47
using System.Threading.Tasks;
58
using NServiceBus.Installation;
69

710
#region InstallSomething
811

9-
public class MyInstaller :
10-
INeedToInstallSomething
12+
public class MyInstaller : INeedToInstallSomething
1113
{
1214
public Task Install(string identity, CancellationToken cancellationToken)
1315
{
@@ -17,4 +19,26 @@ public Task Install(string identity, CancellationToken cancellationToken)
1719
}
1820
}
1921

22+
#endregion
23+
24+
class ShowInstallation
25+
{
26+
public void Snippet(EndpointConfiguration endpointConfiguration)
27+
{
28+
#region AddInstallerFromConfig
29+
endpointConfiguration.AddInstaller<MyInstaller>();
30+
#endregion
31+
}
32+
}
33+
34+
#region AddInstallerFromFeature
35+
36+
public class MyFeature : Feature
37+
{
38+
protected override void Setup(FeatureConfigurationContext context)
39+
{
40+
context.AddInstaller<MyInstaller>();
41+
}
42+
}
43+
2044
#endregion

nservicebus/lifecycle/iwanttorunbeforeconfigurationisfinalized.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ related:
77
- samples/startup-shutdown-sequence
88
---
99

10+
> [!CAUTION]
11+
> `IWantToRunBeforeConfigurationIsFinalized` is deprecated starting in NServiceBus version 10. Refer to the [NServiceBus 10 upgrade guide](/nservicebus/upgrades/9to10/#deprecated-iwanttorunbeforeconfigurationisfinalized).
12+
1013
During endpoint creation the configuration object used to construct the endpoint becomes frozen and locked. Classes that implement `IWantToRunBeforeConfigurationIsFinalized` are instantiated and called just before this happens. Use `IWantToRunBeforeConfigurationIsFinalized` for any last minute alterations to the configuration that may rely on other configuration settings.
1114

1215
Instances are:

nservicebus/operations/installers.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,6 @@ Implement the `INeedToInstallSomething` interface to create a custom installer:
5050

5151
snippet: InstallSomething
5252

53-
Assemblies in the runtime directory are scanned for installers so no code is needed to register them.
53+
### Installer registration
54+
55+
partial: registration
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Assemblies in the runtime directory are scanned for installers so no code is needed to register them.
2+
3+
> [!WARNING]
4+
> In a future version of NServiceBus, [installers will not be scanned and must be registered manually](/nservicebus/upgrades/9to10/#extensibility-installers).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Installers can be added directly to the `EndpointConfiguration`:
2+
3+
snippet: AddInstallerFromConfig
4+
5+
Or from a `Feature` class that requires them:
6+
7+
snippet: AddInstallerFromFeature

nservicebus/pipeline/features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ For a feature to be activated it needs to satisfy the following criteria:
9696
snippet: FeatureSetup
9797

9898
> [!NOTE]
99-
> Features are automatically detected and registered by NServiceBus when the assembly is scanned.
99+
> In NServiceBus version 10 and below, features are automatically detected and registered by NServiceBus when the assembly is scanned. In a future version of NServiceBus [features will not be automatically detected during assembly scanning](/nservicebus/upgrades/9to10/#extensibility-features).
100100
101101

102102
## Feature settings

nservicebus/upgrades/9to10/index.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ Not having a finder configured for a given message will result in:
6060
- **When the message is allowed to start the saga** - Compile time analyzer error [NSB0006](/nservicebus/sagas/analyzers.md#message-that-starts-the-saga-does-not-have-a-message-mapping)
6161
- **When the message is not allowed to start the saga** - `Exception` when processing the message: `Message type CompletePaymentTransaction is handled by saga OrderSaga, but the saga does not contain a property mapping or custom saga finder to map the message to saga data. Consider adding a mapping in the saga's ConfigureHowToFindSaga method`
6262

63+
## Deprecated `IWantToRunBeforeConfigurationIsFinalized`
64+
65+
The extension point [`IWantToRunBeforeConfigurationIsFinalized`](/nservicebus/lifecycle/iwanttorunbeforeconfigurationisfinalized.md) is deprecated with a warning in NServiceBus version 10 and will be removed in NServiceBus version 11.
66+
67+
Final adjustments to settings before configuration is finalized should be applied via an explicit last configuration step on the endpoint configuration, instead of via implementations of this interface discovered by scanning.
6368

6469
## Extensibility
6570

@@ -69,6 +74,55 @@ This section describes changes to advanced extensibility APIs.
6974

7075
As part of adding nullability annotations, the `ContextBag` class no longer allows storing `null` as a value. This also applies to all types derived from `ContextBag`, including all behavior context classes and `TransportTransaction`.
7176

77+
### Features
78+
79+
In a future version of NServiceBus, [`Feature` classes](/nservicebus/pipeline/features.md) will not be automatically discovered by runtime assembly scanning. Instead, each feature should be explicitly enabled for an endpoint.
80+
81+
The preferred method of distributing a feature is to create an extension method on `EndpointConfiguration`, and enable the feature within that extension method:
82+
83+
```csharp
84+
public static class MyFeatureConfigurationExtensions
85+
{
86+
public static void EnableMyFeature(this EndpointConfiguration config)
87+
{
88+
config.EnableFeature<MyFeature>();
89+
}
90+
}
91+
```
92+
93+
The `EnableByDefault()` method is only used to signal that a Feature identified through assembly scanning should turn itself on by default, so this method is deprecated with a warning in NServiceBus version 10 to give advance notice of this change, and will be removed in version 11.
94+
95+
In addition, APIs that work with features using a `Type` have been deprecated, and instead the generic-typed variants should be used. For example:
96+
97+
```csharp
98+
// Instead of:
99+
endpointConfiguration.EnableFeature(typeof(MyFeature));
100+
endpointConfiguration.DisableFeature(typeof(MyFeature));
101+
// Use instead:
102+
endpointConfiguration.EnableFeature<MyFeature>();
103+
endpointConfiguration.DisableFeature<MyFeature>();
104+
```
105+
106+
Lastly, any `Feature` classes must now have a paramaterless constructor.
107+
108+
### Installers
109+
110+
Like features, [installer classes](/nservicebus/operations/installers.md) which implement `INeedToInstallSomething` will not be automatically discovered by runtime assembly scanning in a future version of NServiceBus.
111+
112+
Instead, installers should be explicitly registered either from an `EndpointConfiguration` or inside a feature's `Setup` method:
113+
114+
```csharp
115+
endpointConfiguration.AddInstaller<CreateMyInfrastructure>();
116+
117+
public class MyFeature : Feature
118+
{
119+
protected override void Setup(FeatureConfigurationContext context)
120+
{
121+
context.AddInstaller<CreateMyInfrastructure>();
122+
}
123+
}
124+
```
125+
72126
### StartupDiagnosticEntry has required properties
73127

74128
As part of adding nullability annotations, the `Data` and `Name` properties of the `StartupDiagnosticEntry` class have been marked as `required`.
@@ -109,7 +163,7 @@ The `Supports<TStorageType>(…)` no longer accepts an action that gets access t
109163
public class CustomPersistence : PersistenceDefinition
110164
{
111165
internal CustomPersistence()
112-
{
166+
{
113167
Supports<StorageType.Sagas>(s => s.EnableFeatureByDefault<SagaStorage>());
114168
Supports<StorageType.Subscriptions>(s => s.EnableFeatureByDefault<SubscrptionStorage>());
115169
Supports<StorageType.Outbox>(s => s.EnableFeatureByDefault<OutboxStorage>());
@@ -123,7 +177,7 @@ must be changed to `Supports<TStorageType, TFeatureType>()` like this:
123177
public class CustomPersistence : PersistenceDefinition
124178
{
125179
internal CustomPersistence()
126-
{
180+
{
127181
Supports<StorageType.Sagas, SagaStorage>();
128182
Supports<StorageType.Subscriptions, SubscrptionStorage>();
129183
Supports<StorageType.Outbox, OutboxStorage>();

0 commit comments

Comments
 (0)