Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling installers cause endpoints to fail during startup when the container used is immutable #5296

Closed
WilliamBZA opened this issue Nov 22, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@WilliamBZA
Copy link
Member

WilliamBZA commented Nov 22, 2018

Who's affected

Users configuring a container that is immutable after first resolve like Spring.net and SimpleInjector.

Symptoms

Endpoint fails to start with an exception that container registrations can't be altered after first resolve.

Backported to

7.0.3

Original report

Comes from: WilliamBZA/NServicebus.SimpleInjector#12

The installers are run only after the receive feature is built, meaning that there is an implication that containers must be modifiable after they have already started resolving components. While this is an ok expectation, there is no test to validate that behaviour. Some of the container packages also make the assumption that once they are built they are not going to be modified. This is going to be a problem as more containers move towards being immutable once built (Autofac is probably the next one).

We either need a test to validate that containers can be changed, or we need to change the code so that there are no paths that modify the containers after asking for values from them.

@WilliamBZA WilliamBZA changed the title Installers are run after ReceiveFeature is built Containers are expected to be alterable after being built Nov 22, 2018
@andreasohlund
Copy link
Member

Myself and @WilliamBZA looked at this and at least since v7 we do configure the installers after the first resolve so we need to consider to fix this.

I've verified that spring works so it seems that this only breaks SimpleInjector and future containers that will enforce immutability.

To fix this we would need to move the installer registrations earlier in the code

https://github.com/Particular/NServiceBus/blob/master/src/NServiceBus.Core/InitializableEndpoint.cs#L252

since creating the ReceiveComponent

https://github.com/Particular/NServiceBus/blob/master/src/NServiceBus.Core/InitializableEndpoint.cs#L157

will cause the pipelines to be built and that causes the behaviours to be resolved from the containers.

Should be fairly easy to split and move the installer config but haven't verified

@andreasohlund
Copy link
Member

Turns out that this break spring after all. The sample I tested on used the learning transport which doesn't need installers. Enabling the installers results in spring blowing up with

  Name Value Type
$exception {"Altering the registrations, after the container components has been resolved from the container, is not supported."} System.InvalidOperationException

@andreasohlund andreasohlund added this to the 7.1.5 milestone Dec 3, 2018
@andreasohlund andreasohlund self-assigned this Dec 3, 2018
@andreasohlund andreasohlund changed the title Containers are expected to be alterable after being built Enabling installers cause endpoints to fail during startup when the container used is immutable Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants