From 2769565bce6f62077319cc38caca3b8b740666e1 Mon Sep 17 00:00:00 2001 From: KubaZ2 Date: Thu, 12 Sep 2024 18:14:53 +0200 Subject: [PATCH] Add scopes guide --- Documentation/guides/services/dependency-injection.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/guides/services/dependency-injection.md b/Documentation/guides/services/dependency-injection.md index 7bf6b9c3..d3e3c343 100644 --- a/Documentation/guides/services/dependency-injection.md +++ b/Documentation/guides/services/dependency-injection.md @@ -2,6 +2,12 @@ Dependency injection (DI) is a technique that helps make your code more modular and testable by letting you pass services from the outside. It reduces tight coupling between components, making your applications easier to maintain and extend. +## Scopes + +With `NetCord.Hosting.Services` scopes are created for each command/interaction and disposed after the command/interaction is **completely** executed by default. Therefore all code relevant to the command/interaction like for example the @NetCord.Hosting.Services.ApplicationCommands.ApplicationCommandResultHandler`1 will be executed within the same scope. + +You can control whether to use scopes or not by setting the `UseScopes` property in the options class. For example @NetCord.Hosting.Services.ApplicationCommands.ApplicationCommandServiceOptions`2.UseScopes for application commands. + ## Minimal APIs Dependency injection with minimal APIs can seem complicated at first, but it is actually quite simple.