-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v8 cannot access published content during startup #4572
Comments
Workaround should not be needed - but should not require tons of code to get things to work. Fixing. |
See PR #4577 - and we really should merge this, or anything similar, before releasing. What I have done:
So...
Now, components run before any request, and so don't have a "current" context. They need to explicitely use a context. The following code works on my machine:
Note that withing the The OTOH, if there is no current context, it creates a context, makes it the current one, and returns a reference to that context - and the reference is configured so that when it's disposed, the context is disposed too, and it's de-registered (ie no more current context). This way, if you write code that may run within a request, and also may run outside a request, wrapping things in such a Thoughts? |
This might not be super common but i'm sure it's common enough to need.
Articulate currently accesses the content cache on startup because it needs to define MVC routes based on what routes umbraco has already created for Articulate root nodes.
Currently you can't really access the content cache from within the Initialize method of your composer.
IPublishedSnapshotService
and dovar snapshot = _publishedSnapshotService.CreatePublishedSnapshot(null);
but you will get null ref exceptions when trying return anything from the cache because the PublishContent.cs relies on it's injectedIPublishedSnapshotAccessor
,IUmbracoContextAccessor
,IVariationContextAccessor
, etc... which will all return null at that stage. I'm sure there's some interesting work arounds that can be done with this to force it to work but seems like a lot of code to go through to make that possible.Another oddity is that the IPublishedSnapshotAccessor has a get/set for the
PublishedSnapshot
, however this setter is never used anywhere in umbraco. Also the only implementation ofIPublishedSnapshotAccessor
isUmbracoContextPublishedSnapshotAccessor
which throws when you try to use the setter ... seems this setter shouldn't exist?To work around all of this, what I need to do in Articulate is:
UmbracoApplicationBase.ApplicationInit += UmbracoApplicationBase_ApplicationInit;
app.ResolveRequestCache += App_ResolveRequestCache;
which is the request phase after an UmbracoContext is available but before routing occursThe text was updated successfully, but these errors were encountered: