From ff596964343e6a81b2819cd1d6a8d6901f9737de Mon Sep 17 00:00:00 2001 From: danielmarbach Date: Mon, 11 Mar 2024 10:57:30 +0100 Subject: [PATCH 1/5] Mention MS guidelines and special cases --- .../index_ownership_core_[8.0,).partial.md | 6 ++++++ 1 file changed, 6 insertions(+) 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..f7bac732f71 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) From 14ccec22e85bfd7f1ad696217d31969c0a189593 Mon Sep 17 00:00:00 2001 From: danielmarbach Date: Mon, 11 Mar 2024 11:04:39 +0100 Subject: [PATCH 2/5] Mention ambivalent behavior --- nservicebus/pipeline/manipulate-with-behaviors.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nservicebus/pipeline/manipulate-with-behaviors.md b/nservicebus/pipeline/manipulate-with-behaviors.md index 3f20497a37e..aeaf9e475ec 100644 --- a/nservicebus/pipeline/manipulate-with-behaviors.md +++ b/nservicebus/pipeline/manipulate-with-behaviors.md @@ -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 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 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 icoming message. + partial: options include: mutators-versus-behaviors From 2551ff11d42594b212d9b95f8200d6f3c694b665 Mon Sep 17 00:00:00 2001 From: danielmarbach Date: Mon, 11 Mar 2024 11:11:10 +0100 Subject: [PATCH 3/5] Link --- .../dependency-injection/index_ownership_core_[8.0,).partial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f7bac732f71..cc40ff6195d 100644 --- a/nservicebus/dependency-injection/index_ownership_core_[8.0,).partial.md +++ b/nservicebus/dependency-injection/index_ownership_core_[8.0,).partial.md @@ -82,4 +82,4 @@ When hosting NServiceBus with the [Microsoft Generic Host](https://docs.microsof 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) +- [Injecting dependencies into behaviors](/nservicebus/pipeline/manipulate-with-behaviors.md) From bf67c7ccd473021cfc9ea20228c230b68d5cf10b Mon Sep 17 00:00:00 2001 From: danielmarbach Date: Mon, 11 Mar 2024 11:14:00 +0100 Subject: [PATCH 4/5] Link stages --- nservicebus/pipeline/manipulate-with-behaviors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nservicebus/pipeline/manipulate-with-behaviors.md b/nservicebus/pipeline/manipulate-with-behaviors.md index aeaf9e475ec..7b6c475d29c 100644 --- a/nservicebus/pipeline/manipulate-with-behaviors.md +++ b/nservicebus/pipeline/manipulate-with-behaviors.md @@ -93,7 +93,7 @@ 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 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 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 icoming message. +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. partial: options From 8746fe1ceb2b4310eec0105db07d5b5ce770f75f Mon Sep 17 00:00:00 2001 From: Daniel Marbach Date: Mon, 11 Mar 2024 13:29:21 +0100 Subject: [PATCH 5/5] Update nservicebus/pipeline/manipulate-with-behaviors.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andreas Öhlund --- nservicebus/pipeline/manipulate-with-behaviors.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nservicebus/pipeline/manipulate-with-behaviors.md b/nservicebus/pipeline/manipulate-with-behaviors.md index 7b6c475d29c..901bfbb3e70 100644 --- a/nservicebus/pipeline/manipulate-with-behaviors.md +++ b/nservicebus/pipeline/manipulate-with-behaviors.md @@ -93,7 +93,9 @@ 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. +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