I am trying to extend my Start Page by doing some controller injections with a custom service I have created for Umbraco 8.
The code for the start page looks like this:
public class StartPageController : RenderMvcController
{
private readonly ISiteSettingsPageService _siteSettingsPageService;
public StartPageController(ISiteSettingsPageService siteSettingsPageService)
{
_siteSettingsPageService = siteSettingsPageService;
}
public override ActionResult Index(ContentModel model)
{
var testing = _siteSettingsPageService.GetRootContent();
return Index(model);
}
}
However, I run into trouble with the ISiteSettingsPageService not being registered.
So I tried to follow the IoC documentation for the Umbraco 8 documentation with the following registrations:
public class StartPageComposer : IComposer
{
public void Compose(Composition composition)
{
composition.Register<SiteSettingsPageService, ISiteSettingsPageService>();
}
}
But then I receive "Boot up failure" error message.
I tried to manually edit the Global.asax.cs (which I needed to add after I had created my project) but don't seem to get a hang of it.
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco8.Services;
namespace YourNamespace.Composers
{
public class StartPageComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Register<SiteSettingsPageService, ISiteSettingsPageService>(Lifetime.Request);
}
}
}
It will depend a little on what you are injecting into your SiteSettingsPageService eg something transient UmbracoContext or IPublishedContentQuery...
which should be fine if you are only using your SiteSettingsPageService in a controller, but if you are also trying to inject it into a Component or ContentFinder where the UmbracoContext is not guaranteed to exist, then that can trigger the boot fail error!
Can't register service for RenderMvcController
Hi
I am trying to extend my Start Page by doing some controller injections with a custom service I have created for Umbraco 8.
The code for the start page looks like this:
However, I run into trouble with the ISiteSettingsPageService not being registered.
So I tried to follow the IoC documentation for the Umbraco 8 documentation with the following registrations:
But then I receive "Boot up failure" error message.
I tried to manually edit the Global.asax.cs (which I needed to add after I had created my project) but don't seem to get a hang of it.
Does someone know we this keeps failing for me?
Regards Eric
Hi Eric
There is some work in progress docs here with some examples of creating and injecting your own service:
https://github.com/umbraco/UmbracoDocs/compare/v8/ServicesPattern?short_path=cf2726d#diff-cf2726d2ea2b6f60e0225ce051876a55
try:
It will depend a little on what you are injecting into your SiteSettingsPageService eg something transient UmbracoContext or IPublishedContentQuery...
which should be fine if you are only using your SiteSettingsPageService in a controller, but if you are also trying to inject it into a Component or ContentFinder where the UmbracoContext is not guaranteed to exist, then that can trigger the boot fail error!
regards
Marc
Thanks for the reply, Marc
I do seem to get some kind of boot error for referencing my SiteSettingsPageService from another project?
So the problem seems to still exist even though I swap the service to the same project as the Web project for Umbraco.
My SiteSettingsPageService looks like this:
And the StartPageController like this:
Okay my mistake, I should of course use the CurrentTemplate rendering for the ActionResult rendering:
Was just trying it out locally 'as it all looks right' but yes CurrentTemplate!
So all working for you now? (it's like magic when it works!)
regards
Marc
Yes, nowadays Umbraco feels like a fresh and modern back end solution working with
is working on a reply...