Skip to content

Add DI instructions for dotnet Nexus#4911

Open
Quinn-With-Two-Ns wants to merge 1 commit into
mainfrom
dotnet-di-docs
Open

Add DI instructions for dotnet Nexus#4911
Quinn-With-Two-Ns wants to merge 1 commit into
mainfrom
dotnet-di-docs

Conversation

@Quinn-With-Two-Ns

@Quinn-With-Two-Ns Quinn-With-Two-Ns commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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

@Quinn-With-Two-Ns
Quinn-With-Two-Ns requested a review from a team as a code owner July 17, 2026 16:37
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
temporal-documentation Ready Ready Preview, Comment Jul 17, 2026 4:37pm

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs PR preview links

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants