You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Use dependency injection with a Nexus Service handler {/* #dependency-injection */}
289
+
290
+
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.
291
+
Register the handler on the Worker with `AddScopedNexusService`, and the container injects the handler's constructor dependencies.
292
+
Use `AddSingletonNexusService` or `AddTransientNexusService` for singleton or transient lifetimes instead, mirroring `AddScopedActivities` / `AddSingletonActivities` / `AddTransientActivities`.
293
+
294
+
For a complete, runnable example, see the [NexusDependencyInjection sample](https://github.com/temporalio/samples-dotnet/tree/main/src/NexusDependencyInjection).
// Add the Nexus Service handler at the scoped level
307
+
AddScopedNexusService<GreetingServiceHandler>())
308
+
.Build();
309
+
awaithost.RunAsync();
310
+
```
311
+
312
+
The handler receives its dependencies through its constructor.
313
+
The container creates a new scoped handler instance and its scoped dependencies for each Operation invocation; it does not cache them between invocations:
0 commit comments