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
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 IBrandSearchRepositoryNo matching bindings are available, and the type is not self-bindable.Activation path: 1) Request for IBrandSearchRepositorySuggestions: 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)
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!
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.
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?
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
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.
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.
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!
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.
Can you please post the code to hook up Ninject into Umbraco? Or provide some starting points?
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...
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted