Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Morris 2 posts 22 karma points
    Dec 27, 2013 @ 17:54
    Daniel Morris
    0

    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?

  • Jesper Weber 54 posts 170 karma points c-trib
    Dec 29, 2013 @ 18:00
    Jesper Weber
    0

    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.

  • Jesper Weber 54 posts 170 karma points c-trib
    Dec 30, 2013 @ 17:05
    Jesper Weber
    0

    Extending my Windsor WebApiControllerInstaller to also include controllers from the umbraco.dll solve the problem for me.

  • Daniel Morris 2 posts 22 karma points
    Dec 30, 2013 @ 17:11
    Daniel Morris
    0

    Yeah, I ended up passing in the default resolved into my WindsorDependencyResolver and defaulting to that implementation. Although it does seem a bit ducktapey.

  • Dan 5 posts 27 karma points
    Feb 04, 2014 @ 05:42
    Dan
    0

    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.

  • Mark Stoddard 2 posts 71 karma points c-trib
    Feb 05, 2014 @ 02:05
    Mark Stoddard
    0

    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

  • Dan Mothersole 22 posts 109 karma points
    Feb 07, 2014 @ 14:54
    Dan Mothersole
    0

    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.

     

  • Jesper Weber 54 posts 170 karma points c-trib
    Feb 07, 2014 @ 16:22
    Jesper Weber
    0

    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));
  • Donatello 5 posts 44 karma points
    Feb 08, 2014 @ 01:18
    Donatello
    0

    Having the same exact issue using Autofac. Mark could you share the code you have please?

  • Yakov Lebski 587 posts 2339 karma points
    Feb 13, 2014 @ 18:42
    Yakov Lebski
    0

     var builder = new ContainerBuilder();

                builder.RegisterControllers(typeof(RegistrationController).Assembly);

     

      builder.RegisterApiControllers(typeof (UmbracoApplication).Assembly);

Please Sign in or register to post replies

Write your reply to:

Draft