Add DI instructions for dotnet Nexus#4911
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📖 Docs PR preview links
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8e8885fc84
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ### Use dependency injection with a Nexus Service handler {/* #dependency-injection */} | ||
|
|
||
| Nexus Service handlers support dependency injection through the [Temporalio.Extensions.Hosting](https://github.com/temporalio/sdk-dotnet/tree/main/src/Temporalio.Extensions.Hosting) generic-host Worker. | ||
| Register the handler on the Worker with `AddScopedNexusService`, and the container injects the handler's constructor dependencies. |
There was a problem hiding this comment.
State the SDK version that adds Nexus DI
This reads as if it works with the page's existing prerequisite of Temporal .NET SDK v1.9.0+, but AddScopedNexusService is not present in Temporalio.Extensions.Hosting 1.9.0 and the Nexus service DI helpers appear in 1.13.0+. Users on v1.9-v1.12, which the page still allows, will follow this section and hit a missing-method compile error, so please add the required SDK/Extensions.Hosting version here or update the prerequisite.
Useful? React with 👍 / 👎.
| For a complete, runnable example, see the [NexusDependencyInjection sample](https://github.com/temporalio/samples-dotnet/tree/main/src/NexusDependencyInjection). | ||
|
|
||
| [NexusDependencyInjection/Program.cs](https://github.com/temporalio/samples-dotnet/blob/main/src/NexusDependencyInjection/Program.cs) | ||
| ```csharp |
There was a problem hiding this comment.
All of the code samples should be made snipsync in the features repo.
| await host.RunAsync(); | ||
| ``` | ||
|
|
||
| The handler receives its dependencies through its constructor, and a scoped instance is created for each Operation: |
There was a problem hiding this comment.
and a scoped instance is created for each Operation
Maybe could be more precise here. I think it's better to say that it's created for each operation invocation. Because the question is wether an operation instance is cached or not (and it is not, since it is recreated for each invocation; and that is the desired behavior for scoped services). Because, hypothetically, we could cache the operation instances for single registrations and not have to pay for construction on each invocation.
What does this PR do?
Add DI instructions for dotnet Nexus
Notes to reviewers
Depends on temporalio/samples-dotnet#186
┆Attachments: EDU-6745 Add DI instructions for dotnet Nexus