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

More container guidance #6486

Merged
merged 5 commits into from Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
2 changes: 2 additions & 0 deletions nservicebus/pipeline/manipulate-with-behaviors.md
Expand Up @@ -93,6 +93,8 @@ 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 builder on the context can vary depending on the pipeline stage it is being used in. For every [pipeline stage used within the context of an incoming message](/nservicebus/pipeline/steps-stages-connectors.md#stages-incoming-pipeline-stages) the builder exposes the child service provider created for the incoming message. For all other cases the builder 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 from the context of a message session the builder exposes the root service provider. In cases when the same outgoing behavior is invoked from a message operation within the scope of an incoming message, the builder will be the child service provider for the incoming message.
danielmarbach marked this conversation as resolved.
Show resolved Hide resolved

partial: options

include: mutators-versus-behaviors