diff --git a/nservicebus/dependency-injection/index_ownership_core_[8.0,).partial.md b/nservicebus/dependency-injection/index_ownership_core_[8.0,).partial.md index a1ccd2d2ab9..cc40ff6195d 100644 --- a/nservicebus/dependency-injection/index_ownership_core_[8.0,).partial.md +++ b/nservicebus/dependency-injection/index_ownership_core_[8.0,).partial.md @@ -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) diff --git a/nservicebus/pipeline/manipulate-with-behaviors.md b/nservicebus/pipeline/manipulate-with-behaviors.md index 3f20497a37e..901bfbb3e70 100644 --- a/nservicebus/pipeline/manipulate-with-behaviors.md +++ b/nservicebus/pipeline/manipulate-with-behaviors.md @@ -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