Hi,
I have these:
And
And it fails like this:
How can I use my sessionToolbox inside OnCommandExceptionAsync() ?
PS:
I also want to set session entry
![]()
Hi,
I have these:
And it fails like this:
How can I use my sessionToolbox inside OnCommandExceptionAsync() ?
PS:
I also want to set session entry
![]()
Unfortunately, dependency injection does not work into the DotvvmStartup class, since it can also configure service container itself. You have to explicitly call config.Services.GetRequiredService<SessionToolbox>() to obtain the service you want to pass to the action filter.
It crashes the app with this:
âCannot resolve scoped service âNGM.Services.SessionToolboxâ from root provider.â
Am I calling it wrong or missing something? I already tried adding SessionToolbox as transient/scoped/singleton service in Program.cs (.NET 8 web app).
PS:
I can also obtain the service in Program.cs:

I got it to work.
For some reason (that I donât understand), apart from the âGetRequiredServiceâ line, I needed to also add services in ConfigureServices() of DotvvmStartup.cs:

The attribute will be a singleton, so it will break if you service is stateful. I think you should either make the service singleton too, or call GetRequiredService inside the attribute method â then even Scoped should work fine.