Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/user/app_model/app_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyApp> 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.

Expand Down