Skip to content

Commit

Permalink
More container guidance (#6486)
Browse files Browse the repository at this point in the history
* Mention MS guidelines and special cases

* Mention ambivalent behavior

* Link

* Link stages

* Update nservicebus/pipeline/manipulate-with-behaviors.md

Co-authored-by: Andreas Öhlund <andreas.ohlund@particular.net>

---------

Co-authored-by: Andreas Öhlund <andreas.ohlund@particular.net>
  • Loading branch information
danielmarbach and andreasohlund committed Mar 11, 2024
1 parent 2966ad8 commit 5742e1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Expand Up @@ -77,3 +77,9 @@ The [NServiceBus.Extensions.DependencyInjection Usage sample](/samples/dependenc
## Microsoft Generic Host

When hosting NServiceBus with the [Microsoft Generic Host](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host) using the `NServiceBus.Extensions.Hosting` package, refer to the [configure custom containers documentation](/nservicebus/hosting/extensions-hosting.md#dependency-injection-integration-configure-custom-containers) for further details.

## Resolving dependencies

It is recommended to follow the [dependency injection guidelines](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines) for .NET. Be aware of the following special cases with NServiceBus:

- [Injecting dependencies into behaviors](/nservicebus/pipeline/manipulate-with-behaviors.md)
4 changes: 4 additions & 0 deletions nservicebus/pipeline/manipulate-with-behaviors.md
Expand Up @@ -93,6 +93,10 @@ snippet: InjectingDependencies

Dependencies injected into the constructor of a behavior become singletons regardless of their actual scope on the dependency injection container. In order to create instances per request or scoped dependencies it is required to use the builder that is available on the context.

The service provider available via the context varies depending on the pipeline stage. [Pipeline stages used within the context of an incoming message](/nservicebus/pipeline/steps-stages-connectors.md#stages-incoming-pipeline-stages) exposes a new child service provider created for each incoming message. All other use cases exposes the root service provider.

Behaviors in the [outgoing pipeline stage](/nservicebus/pipeline/steps-stages-connectors.md#stages-outgoing-pipeline-stages) exhibit different behaviors depending on how they are invoked. For example, when an outgoing behavior is invoked within the context of a message session the root service provider is exposed while when the same outgoing behavior is invoked within the scope of an incoming message, the child service provider for the incoming message will be used.

partial: options

include: mutators-versus-behaviors

0 comments on commit 5742e1f

Please sign in to comment.