man-group / dapr-sidekick-dotnet

Dapr Sidekick for .NET - a lightweight lifetime management component for Dapr
Apache License 2.0
177 stars 21 forks source link

DaprSidekick appsetting section ignored? #47

Closed ijn-kruso closed 1 year ago

ijn-kruso commented 1 year ago

Hello - first of all, thanks for all the great work on this project!

I'm trying to configure DaprSidekick with a custom components folder. For that I tried adding the config: { "DaprSidekick": { "ComponentsDirectory": "dapr-components" } }

I tried initializing using builder.Services.AddDaprSidekick(); and builder.Services.AddDaprSidekick(builder.Configuration);

Both times the setting are ignored and the components are taken from the default dapr installation folder. Are there anything I'm missing here, or it a bug?

EDIT: After some debugging I got it working by using the alternative AddDaprSidekick method (not using appsettings): builder.Services.AddDaprSidekick(delegate(DaprOptions options) { options.Sidecar ??= new DaprSidecarOptions(); options.Sidecar.ComponentsDirectory = "dapr-components"; });

Of course I'd still very much like to have it working with appsettings.json instead.

badgeratu commented 1 year ago

Hi, and thanks for your interest in Sidekick! Many options are common across the Sidecar, Placement and Sentry definitions and so can be put in the top-level "DaprSidekick" section in appsettings.json allowing defaults to be set for all three hosted processes in one place (depending on what a service needs). However some settings are specific to that hosted process and need to go into their own sub-section for that process. In this case ComponentsDirectory is specific to the Sidecar process so the actual definition you need is:

{ "DaprSidekick": { "Sidecar" : { "ComponentsDirectory": "dapr-components" } } }

And you're correct that to ensure Sidekick loads these settings from configuration you use the following:

builder.Services.AddDaprSidekick(builder.Configuration);
ijn-kruso commented 1 year ago

I feel a bit stupid now :) I'll add the correct app settings to my project, thanks a lot for the help!