Closed rserj closed 3 years ago
cc: @jtkech
Yes during setup we use an internal shell with an internal shell settings at some point, but normally in a given scope you should get the same values, I will take a look tommorow
In place of testing ShellScope.Context.IsActivated
try to check if ShellScope.Context.Settings.State
is not initializing or just is running, because during setup a shell is activated multiple time while still being initializing. And because you have a service provider you can just use the resolved shellSettings.
We alreay have a redis module that includes e.g. a data protection feature
Yeh, I saw the feature OrchardCore.Redis.DataProtection, thank you
try to check if ShellScope.Context.Settings.State is not initializing
As I remember it was in Running State and I still couldn't get section values but can be mistaken.
What I know is ShellScope.Context.Settings.State != serviceProvider.GetRequiredService<ShellSettings>().State
I will take a look tommorow
Thank you very much
Okay, calling the modules ConfigureServices()
(and the ones defined through our app level helpers) means that we are building the shell, so here it can't be activated, you are not executing in a scope context but in a tenant / shell context, the one we are composing, so the Context
prop of ShellScope
may be null.
What happens is that during a setup, or through some other services e.g. when a tenant depend on another one that is not yet composed, this is in the context of a given shell scope that we are building a shell context, so here you may get the ShellScope of a parent, which doesn't happen when really running in a scope context, which is not the case here.
The service provider that we pass here is a tenant service provider not a scoped one so no shell scope that can be used, this is in the Configure()
methods when building the tenant pipeline that we pass a scoped service provider.
So here you should only use serviceProvider.GetRequiredService<ShellSettings>()
to resolve the shellSettings which is a tenant singleton, and then check the settings state, e.g. if settings.State == TenantState.Running
, as we do in our AddAntiForgery()
extension.
@jtkech Thank you for detailed explanation
I use
OrchardCoreBuilder.ConfigureServices((services, serviceProvider) =>
extension. It's get called many times during Setup/Autosetup(I think it happens when Features get enabled and Orchard rebuilding the whole Shell's Blueprint is this right? ) and sometimes I can not extract the configuration section for shell/tenant
redisConnection
is null the same behavior if I get a section value via