Ninject MVC3 – bootstrapper throwing “Already Initialized” exception

Take a look at Setting up a MVC3-application In short: You probably have een App_Start folder in your project with a NinjectMVC3.cs file. When using the NuGet package in combination with modifying the Global.asax (for which there is no reason) you have to remove the App_Start folder and remove the references to WebActivator and Microsoft.Web.Infrastructure

Configuring Ninject with Asp.Net MVC & Web Api

I have written some gists to help configure Ninject with MVC and Web Api. Simply include the file(s): https://gist.github.com/odytrice/5821087 (for MVC) https://gist.github.com/odytrice/5842010 (for WebApi) To add Bindings for concrete Types, Just put them in the Load() method of the MainModule. You can create as many modules as you like to keep bindings organized. but you’ll … Read more

Dependency injecting UserStore in OWIN startup using Ninject OWIN middleware

For info: It is possible to register the kernel as a singleton so that the same kernel can be used by the ninject middleware and also registered within the owin context. public static StandardKernel CreateKernel() { if (_kernel == null) { _kernel = new StandardKernel(); _kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); _kernel.Load(Assembly.GetExecutingAssembly(), Assembly.Load(“Super.CompositionRoot”)); } return _kernel; } The callback function … Read more

Where should I do Injection with Ninject 2+ (and how do I arrange my Modules?)

I don’t know NInject, but unless it works vastly different than Windsor, StructureMap etc. the answers tend to stay the same, as there are some common DI patterns. With that in mind: The first thing to realize is that DI isn’t tied to a particular framework such as NInject or Windsor. It is a set … Read more

ASP.NET MVC 4 + Ninject MVC 3 = No parameterless constructor defined for this object

I know this is an old question but there don’t seem to be any real answers and I’ve worked around the problem so here is my solution: Create a custom controller factory: public class NinjectControllerFactory : DefaultControllerFactory { private IKernel ninjectKernel; public NinjectControllerFactory(IKernel kernel) { ninjectKernel = kernel; } protected override IController GetControllerInstance(RequestContext requestContext, Type … Read more

NInject with Generic interface

This should work:- Bind(typeof(IRepository<>)).To(typeof(Repository<>)); where:- IRepository<> is an interface of the form:- public interface IRepository<T> where T : class { //… } Repository<> is a class of the form:- public class Repository<T> : IRepository<T> where T : class { //… } I hope this helps 🙂

Translate ninject ISecureDataFormat binding to Autofac

The migration from Ninject to Autofac seems to be correct, but the binding for the ISecureDataFormat<AuthenticationTicket> interface may not be working as expected, leading to an activation error in some dependencies. Based on the debugging messages, the BearerTokenCookieStore class is failing to resolve this dependency. In the Ninject version, ISecureDataFormat<AuthenticationTicket> is bound to a method … Read more

NInject: Where do you keep your reference to the Kernel?

It’s true that you don’t want to pass around the kernel. Typically, in a web app, I store the kernel in a static property in the HttpApplication. If you need a reference to the kernel, you can just expose a dependency (via constructor argument or property) that is of the type IKernel, and Ninject will … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)