I'm trying to extend Umbraco 8 and i need to access the Services, Contentype Service, memberservice ETC during startup.
Usually i would use the old OnApplicationStarted and Application context like so:
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ApplicationContext.Current.Services.ContentService.GetById(someId);
}
Trying to do the same in umbraco 8 i've hit a wall though. I've come up witht the following:
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class Startup : IUserComposer
{
void IComposer.Compose(Composition composition)
{
var x = Current.Services.ContentTypeService.GetAllContentTypeAliases();
The issue is that any attempts to get any services results in the error that Factory is not set.
Does anyone know a way around this ? Am i doing it completely wrong?
Thank you. It seems like you linked to this article ?
Anyway after writing this post i changed my code to Subscribe to UmbracoApplicationBase.ApplicationInit.
In this method i have access to the services. Only issue is it seems this event is called multiple times, so i cannot use it to map a new route in the route table.
Content services during boot / composing
Hi.
I'm trying to extend Umbraco 8 and i need to access the Services, Contentype Service, memberservice ETC during startup.
Usually i would use the old OnApplicationStarted and Application context like so:
Trying to do the same in umbraco 8 i've hit a wall though. I've come up witht the following:
The issue is that any attempts to get any services results in the error that Factory is not set.
Does anyone know a way around this ? Am i doing it completely wrong?
Thanks alot
Here's some documentation that shows you how to do it: https://our.umbraco.com/Documentation/Implementation/Composing/#example---creating-a-component-to-listen-for-contentservicesaving-events
You're currently doing it in the place where you should be registering your component.
Your component's
Initialize()
method is responsible for hooking into the event, you can't do it in theIUserComposer
:)Thank you. It seems like you linked to this article ?
Anyway after writing this post i changed my code to Subscribe to UmbracoApplicationBase.ApplicationInit.
In this method i have access to the services. Only issue is it seems this event is called multiple times, so i cannot use it to map a new route in the route table.
Ah how silly, I've updated the link to: https://our.umbraco.com/Documentation/Implementation/Composing/#example---creating-a-component-to-listen-for-contentservicesaving-events
Nope, please don't. :-)
is working on a reply...