From 4c5d572d43eaece9a9fc483858dc0b49831bac23 Mon Sep 17 00:00:00 2001 From: Szymon Zywert Date: Fri, 28 Aug 2026 15:22:23 +0200 Subject: [PATCH] Document ICurrentApp for getting the current app id --- docs/user/app_model/app_model.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/user/app_model/app_model.md b/docs/user/app_model/app_model.md index fec9df6..fac883a 100644 --- a/docs/user/app_model/app_model.md +++ b/docs/user/app_model/app_model.md @@ -134,6 +134,28 @@ public sealed class LifeTimeApp : IAsyncInitializable, IAsyncDisposable } ``` +### Knowing which app you are + +Inject `ICurrentApp` to find out the id of the app that owns the current +dependency injection scope. This is useful when a service is shared between apps +and needs to pick up per-app configuration or logging. + +```csharp +[NetDaemonApp] +public class MyApp +{ + public MyApp(ICurrentApp currentApp, ILogger logger) + { + logger.LogInformation("Running as app {AppId}", currentApp.Id); + } +} +``` + +`ICurrentApp.Id` is the same id NetDaemon uses everywhere else: the `Id` set on +the `[NetDaemonApp]` attribute when present, otherwise the full name of the app +type. It can also be resolved from any other service that is registered in the +app's scope. + ### Minimal app lifecycle events A minimal app consists of just a single delegate. When the app is started, its parameters are resolved from the DI container and the delegate is invoked. A minimal app can implement async initialisation by providing an async delegate (that returns a Task, ValueTask, or other awaitable object) the runtime will the await its return value during initialisation.