Copied to clipboard

Flag this post as spam?

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


  • Steen Tøttrup 191 posts 291 karma points c-trib
    Dec 21, 2010 @ 15:56
    Steen Tøttrup
    0

    Using Ninject with Umbraco?

    Okay, so I've been building a website where a lot of the data presented is located in an external database.

    I've build a bunch of repositories that access this data. For now I've been using LINQ to SQL, but plan on changing that later, so I've been using Ninject for my DI framework.

    To make all the mappings happen, I'm using an implementation of ApplicationBase.

    The very odd thing is that somewhere along the way, it looks like Ninject looses all mappings.

    It starts failingout of the blue.

    ------------------------------
    Error activating IBrandSearchRepository
    No matching bindings are available, and the type is not self-bindable.
    Activation path:
      1) Request for IBrandSearchRepository

    Suggestions:
      1) Ensure that you have defined a binding for IBrandSearchRepository.
      2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
      3) Ensure you have not accidentally created more than one kernel.
      4) If you are using automatic module loading, ensure the search path and filters are correct.

       at Ninject.KernelBase.Resolve(IRequest request)
       at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters)
       at XXX.Core.ObjectFactory.GetInstance[T]()
       at XXX.Core.SearchHelper.BrandSearch(String categoryString, String male)
       at XXX.Umbraco.Extension.GetBrands(String category, String male)

    Any ideas?

    I haven't seen this in other apps where I've used Ninject, so could this have something to do with ApplicationBase or..??

    Any help is appriciated!

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Dec 22, 2010 @ 03:02
    Aaron Powell
    0

    Isn't Ninject meant to hook into the Global.asax? That's how other DI frameworks I've worked with operate. By extending that class there is always a place that you can access your kernel, via HttpContext.Current.ApplicationInstance (and then cast it as an interface from your IoC container).

    I wouldn't rely on ApplicationBase to be useful for an IoC container, it's really not designed to work that way.

  • Steen Tøttrup 191 posts 291 karma points c-trib
    Dec 22, 2010 @ 06:45
    Steen Tøttrup
    0

    In a regular ASP.NET application you would use global.asax to configure the bindings (on application start), that's why I'm using ApplicationBase. I just need to make sure that Ninject is configured with the right bindings.

    I've got my own static/singleton class that I'm using to get to the kernel, and everything seems to be working, until all of a sudden Ninject has lost all bindings.

    Any other way of making sure this happens on application start?

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Dec 22, 2010 @ 07:40
    Aaron Powell
    0

    Yeah but if ninject is like other IoC containers it needs to be able to find its way back to the kernel object. Because you're not putting it on the ApplicationInstance class it doesn't know where it is.

    Umbraco shouldn't be treated differently to any other ASP.Net application in regards to IoC

  • Steen Tøttrup 191 posts 291 karma points c-trib
    Dec 22, 2010 @ 09:29
    Steen Tøttrup
    0

    Well, I have to treat it a bit differently, as I can't put things in global.asax :)

    And other than that, I'm using Ninject in the exact same way as I'm using it in the MVC apps I've made lately.

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Dec 22, 2010 @ 10:13
    Aaron Powell
    0

    Why not? I do it all the time.

    Delete App_global.dll and either inherit from umbraco.Global (if you want to inherit the Umbraco one which does nothing) or create your own class inheriting HttpApplication and change what the Global.asax file points to.

  • Steen Tøttrup 191 posts 291 karma points c-trib
    Dec 22, 2010 @ 13:09
    Steen Tøttrup
    0

    Ah, been browsing through a lot of the global.asax threads, but I never came across that solution!

    Thanks, I'll give that a go!

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Dec 23, 2010 @ 01:56
    Aaron Powell
    0

    I'm sure that I said that in at least one of them and everyone kept linking to the post :P

    I thought I heard it was being removed from Juno since there was nothing the Global.asax does, but it might just be a fix so that the App_Global.asax.dll is being removed.

  • Mounhim Tahtahi 41 posts 62 karma points
    May 17, 2013 @ 11:52
    Mounhim Tahtahi
    0

    Can you please post the code to hook up Ninject into Umbraco? Or provide some starting points?

  • Thomas Morris 35 posts 133 karma points MVP 2x c-trib
    May 30, 2013 @ 12:47
    Thomas Morris
    1

    I wasn't able to get it working within Umbraco 4.11.6 using the Global.asax method, so decided to just use NuGet to install the latest Ninject.Web package. This adds a App_Start folder to your App_Code folder with a couple of files to handle the bindings. Just add the following to the RegisterServices method and you should be good to go...

    kernel.Bind<IService>().To<LocalService>();

Please Sign in or register to post replies

Write your reply to:

Draft