Introduce .Services on EndpointConfiguration as a replacement for RegisterComponents#7643
Introduce .Services on EndpointConfiguration as a replacement for RegisterComponents#7643danielmarbach wants to merge 1 commit intomasterfrom
Conversation
|
We are keeping this as draft and rediscussing it. |
| s.AddSingleton<SingletonAsyncDisposable>(); | ||
| }); | ||
| // We have to take control over re-registering the context because we have taken control over the instance creation | ||
| c.Services.AddSingleton((Context)r.ScenarioContext); |
There was a problem hiding this comment.
This is unique to this test, not unique to moving from RegisterComponents to Services.Add… right?
| [ObsoleteMetadata(Message = "Use the Services property instead", | ||
| ReplacementTypeOrMember = "EndpointConfiguration.Services", | ||
| TreatAsErrorFromVersion = "11", | ||
| RemoveInVersion = "12")] |
There was a problem hiding this comment.
ReplacementTypeOrMember is only a shortcut for when you don't specify a more specific string. Note in the generated message you essentially get duplicate sentences when you provide both properties. Also, an edit suggestion:
| [ObsoleteMetadata(Message = "Use the Services property instead", | |
| ReplacementTypeOrMember = "EndpointConfiguration.Services", | |
| TreatAsErrorFromVersion = "11", | |
| RemoveInVersion = "12")] | |
| [ObsoleteMetadata(Message = "Use the Services property for direct access to the endpoint-specific IServiceCollection instead", | |
| TreatAsErrorFromVersion = "11", | |
| RemoveInVersion = "12")] |
Will require running the fixer (I don't trust myself to guess) and then also updating the API approval.
andreasohlund
left a comment
There was a problem hiding this comment.
Assuming Davids remark about the obsolete message gets addressed
|
We'll do it differently. I will resurrect some things from here, but we are not proceeding. I'll keep you posted |
This PR introduces a new
EndpointConfiguration.Servicesproperty as the preferred way to register custom services with the dependency injection container, and deprecates the existingRegisterComponents(Action<IServiceCollection>)method.Motivation
We want to deprecate
RegisterComponentson endpoint configuration because:Tradeoff Analysis
Option 1: Lambda on AddNServiceBusEndpoint(IServiceCollection services, Action configure)
Rejected
This would have users configure services when calling
AddNServiceBusEndpoint:Why rejected:
Option 2: EndpointConfiguration.Services Property (Selected)
This exposes an IServiceCollection directly on the configuration:
Why selected:
Implementation challenge: Since EndpointConfiguration is created before the actual service collection exists, we use a staging collection pattern:
Changes
New API:
Deprecated:
Behavior:
Migration Guide
Before (obsolete):
After: