Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I've installed LightInject MVC for my IOC and i'm getting a strange error in the back office, It won't render the tree. The front end still serves content pages but with LightInject being called I can't use the tree in the backoffice. If I comment out the line container.EnableMvc(); for LightInject, then it works but then it doesn't inject my dependencies.
Can anyone shed any light please?
I'm running VS 2015 & SQL Server 2014 on Windows 8.1 Pro.
The nuget versions i've got installed are:
My lightinject config is:
public class LightInjectConfiguration
public static void Execute()
var container = new ServiceContainer();
// If I comment out this line, I don't get the exception but I don't know why.
My StackTrace is:
Received an error from the server
Failed to retrieve data for application tree content
Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Umbraco.Web.Trees.ApplicationTreeExtensions.TryLoadFromControllerTree(ApplicationTree appTree, String id, FormDataCollection formCollection, HttpControllerContext controllerContext)
Never used light inject. But for Autofac you need to do some additional registration.
Here is our autofac code set up :
Maybe this can help you solve the issue.
var builder = new ContainerBuilder();
// Register the UmbracoContext as a factory, the controllers require this in their constructor
builder.Register(c => UmbracoContext.Current).AsSelf();
// register controllers
// register umbraco application context
// register your interfaces here
// create container
var container = builder.Build();
// setup the mvc dependency resolver to user autofac
var resolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = resolver;
Thanks for getting in touch. I'll try out using AutoFac using your suggested config above and i'll let you know how I get on.
LOL was hoping that you got it working with Light Inject. Umbraco core has this on the roadmap as IOC container.
I've played a little bit with LightInject too (mostly because I heard that it would be used in v8 like Dave mentioned above :)).
I also struggled with the same error + a lot more issues with additional packages and libraries used in solution to which I wanted to add this IoC container.
First of all, we need to also instal LightInject.WebApi package and register all api controller within our app. It solves some of the errors, but in my case, many of them were still occuring (for example with Umbraco Forms).
I found some discussions, for example: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/61745-Failed-to-retrieve-data-for-application-tree-forms-AutoFac-IOC-Umbraco-722-and-Forms and figured out that registration of specific DLLs is helping out to cover their unregistered services. Reading more and more about it, mostly inside a lot of posts by author of LightInject on StackOverflow (http://stackoverflow.com/users/800103/seesharper) I found that we need to perform some kind of scan of used libraries and dependencies and register them too. I found a method inside source code responsible for registration of WebApi controllers and adopted it a little bit to help me out performing the same for my "lost" dependencies.
My complete code responsible for registration of container:
var container = new ServiceContainer();
//// We need to register used typed for all assemblies in domain / app
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
var controllerTypes = assembly.GetTypes().Where(t => !t.IsAbstract && typeof(IHttpController).IsAssignableFrom(t));
foreach (var controllerType in controllerTypes)
container.Register(controllerType, new PerRequestLifeTime());
//// Umbraco / CurrentAssebly registrations (+ API)
//// Custom interfaces and services
container.Register<IFoo>(factory => new Foo(container.GetInstance<IBar>());
And now it's working! Going to test it deeply and compare performance with previously one achieved with Ninject. Happy coding!
Be careful if you want to use LightInject with Umbraco Cloud. See this topic: https://our.umbraco.org/forum/umbraco-cloud/89853-using-lightinject-on-umbraco-cloud
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted