In Umbraco 6 I was able to successfully use the DependencyResolver.SetResolver to an implementation of a WindsorDependencyResolver to get dependency injection working. However, when I try to use that same strategy in Umbraco 7, I receive an error saying "Failed to retreive data for application tree content" when signing in to the cms. It's getting a NullReferenceException in "Umbraco.Web.Trees.ApplicationTreeExtensions.TryLoadFromControllerTree". There are no line numbers associated, so it's hard to say exactly where that is happening. I've looked at the source and can see no reason for this failure. As soon as I comment out the DependencyResolver.SetResolver, everything goes back to normal. Any ideas?
I'm having the same issue, using Umbraco 7.0.1 and Castle Windsor. When setting the DependencyResolver I can use dependency injection in my RenderMvcControllers used in the frontend, but the backoffice is not working (I also get the NullReferenceException in the ApplicationTreeExtentions). When not setting the DependencyResolver the bakoffice works just fine, but then of cause my RenderMvcControllers can not be resolved when using dependency injection.
Yeah, I ended up passing in the default resolved into my WindsorDependencyResolver and defaulting to that implementation. Although it does seem a bit ducktapey.
I'm having the same issue but using StructureMap as my DI framework. I've isolated the issue down to the dependency resolver for the WebAPI not being able to resolve the UmbracoApiController(s) defined in the umbraco.dll also.
You've mentioned that you included controllers from the umbraco.dll in your Windsor container to fix the issue. Would you be able to post a code snippet on how you did that?
Trying to figure out what the equivalent is in StructureMap. I don't really want to have to register EVERY single type that is required from the umbraco.dll, as it may change, and would be extremely tedious.
I'm experiencing the same thing with Autofac. I can resolve the Umraco controllers just fine if I register them one at a time, but not if I try to register the assembly containing them.
As I mentioned I solve the problem by extending my WebApiControllerIntaller to also include the umbraco.dll. I don't know if this is the right way to do it, but it works for me.
My solution using Castle Windsor
public class WebApiControllerInstaller : IWindsorInstaller
{
private readonly Assembly[] _assembliesContainingWebApiControllers;
public WebApiControllerInstaller(params Assembly[] assembliesContainingWebApiControllers)
{
_assembliesContainingWebApiControllers = assembliesContainingWebApiControllers;
}
public void Install(IWindsorContainer container, IConfigurationStore store)
{
foreach (var assembliesContainingWebApiController in _assembliesContainingWebApiControllers)
{
container.Register(Classes.FromAssembly(assembliesContainingWebApiController)
.BasedOn<IHttpController>()
.If(t => t.Name.EndsWith("Controller"))
.Configure((c => c.LifestyleTransient())));
}
}
}
var websiteAssembly = typeof(Website.Properties.AssemblyIdentifier).Assembly;
var umbracoAssembly = typeof(UmbracoApplication).Assembly;
var container = new WindsorContainer();
container.Install(new WebApiControllerInstaller(websiteAssembly, umbracoAssembly));
Castle Dependency Resolver causes error
In Umbraco 6 I was able to successfully use the DependencyResolver.SetResolver to an implementation of a WindsorDependencyResolver to get dependency injection working. However, when I try to use that same strategy in Umbraco 7, I receive an error saying "Failed to retreive data for application tree content" when signing in to the cms. It's getting a NullReferenceException in "Umbraco.Web.Trees.ApplicationTreeExtensions.TryLoadFromControllerTree". There are no line numbers associated, so it's hard to say exactly where that is happening. I've looked at the source and can see no reason for this failure. As soon as I comment out the DependencyResolver.SetResolver, everything goes back to normal. Any ideas?
I'm having the same issue, using Umbraco 7.0.1 and Castle Windsor. When setting the DependencyResolver I can use dependency injection in my RenderMvcControllers used in the frontend, but the backoffice is not working (I also get the NullReferenceException in the ApplicationTreeExtentions). When not setting the DependencyResolver the bakoffice works just fine, but then of cause my RenderMvcControllers can not be resolved when using dependency injection.
Extending my Windsor WebApiControllerInstaller to also include controllers from the umbraco.dll solve the problem for me.
Yeah, I ended up passing in the default resolved into my WindsorDependencyResolver and defaulting to that implementation. Although it does seem a bit ducktapey.
Hi guys,
I'm having the same issue but using StructureMap as my DI framework. I've isolated the issue down to the dependency resolver for the WebAPI not being able to resolve the UmbracoApiController(s) defined in the umbraco.dll also.
You've mentioned that you included controllers from the umbraco.dll in your Windsor container to fix the issue. Would you be able to post a code snippet on how you did that?
Trying to figure out what the equivalent is in StructureMap. I don't really want to have to register EVERY single type that is required from the umbraco.dll, as it may change, and would be extremely tedious.
Thanks,
Dan.
I'm experiencing the same thing with Autofac. I can resolve the Umraco controllers just fine if I register them one at a time, but not if I try to register the assembly containing them.
Mark
Is there any news on a fix for this issue? I am going to create a bug report unless I find that someone else has.
We are using Autofac per the Umbraco documentation but are having the same issue as others.
As I mentioned I solve the problem by extending my WebApiControllerIntaller to also include the umbraco.dll. I don't know if this is the right way to do it, but it works for me.
My solution using Castle Windsor
Having the same exact issue using Autofac. Mark could you share the code you have please?
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(RegistrationController).Assembly);
builder.RegisterApiControllers(typeof (UmbracoApplication).Assembly);
is working on a reply...