ninject

how to use AsyncController in MVC application using Ninject for DI ?

Does anyone know how to use an AsyncController in a mvc application that uses Ninject for DI? AsyncController works fine when i dont use ninject but i cant make them work together. I added following in my sitemodule but no go. Bind<IAsyncController>( ).To<AsyncController>( ).InSingletonScope( ); sorry for not explaining this in de...

Is it possible to change how MEF creates imported objects?

I would like to use MEF to find my extensions but keep the responsibility for creating them to Ninject or a custom factory. Is that possible? ...

Ninject Intermittent exception thrown related to OnePerRequestModule

I just upgraded an existing implementation of Ninject from 1.5 to 2.0. I'm now seeing an intermittent exception getting thrown when many requests are happening in a short period of time. Here's the exception that is being thrown. Type: System.ArgumentException Message: An item with the same key has already been added. Source: ...

Does Ninject automatically inject non-bound classes?

public class MyController : Controller { private MyClass _class; public MyController(MyClass class) { this._class = class; } } public class MyClass { // stuff } My Ninject is hooked up to inject classes that implement IController (Controller class does so). But, I did not bind MyClass to anything, yet Ninject...

Ninject 2 with MVC 2 Case Sensitive Controller Names

I have a new MVC 2 project using ninject 2 for IOC. I have the following global.asax which sets up both NHibernate and Ninject. The code runs fine, ninject pulls out the controllers from the assembly (it does convert them to lowe case strings when it does this - inside the Ninject source). All my controller URL's are now case sensitive ...

In Ninject 2, how do I have two Kernels with different settings share bindings?

I have a single Ninject 2 Kernel for my application which contains all bindings. One section of the application needs to have different settings on the Kernel than the rest of the application, but needs the same bindings (that portion is for NHibernate and needs InjectNonPublic = true and the InjectAttribute set). How can a make a Kern...

Why does the generated NinjectMVC3.cs from NuPack not compile? (or what happened to MvcServiceLocator in ASP.NET MVC 3 Beta? )

Using the NuPack addin and installing the NInject MVC 3 package results in the following compile error in the generated NinjectMVC3.cs file. The name 'MvcServiceLocator' does not exist in the current context The sample video David Ebbo posted shows it working just fine at 09:43. Here is the currently generated class: public class Nin...

ASP.NET MVC, Ninject, single instance per request for multiple constructors

Im trying to implement an unit of work pattern by passing an unit of work instance into my repositories. Relevant code from Global.asax. public class SiteModule : NinjectModule { public override void Load() { Bind<IUnitOfWork>().To<SqlUnitOfWork>() .InRequestScope() ...

Ninject.Web (webforms extension), injecting outside of a webform page?

I've been using the Ninject.Web extension to inject business objects, repositories, Entity Framework context etc into my application. This works very well using the [Inject] attribute which can be applied within a webform that inherits from PageBase. I am now running into a snag as I am trying to write a custom membership provider that...

ASP.NET MVC MembershipProvider with repository and ninject

How do I communicate with the UserService through an overidden MembershipProvider class? I have no idea how to pass the connection string to the user repository inside the service. This is how my app is structured: Repository (constructor in the implementation takes a connection string) public interface IUserRepository { IQueryabl...

Ninject and forwarded types (as it's known in Castle Windsor)

In Castle Windsor there is a feature called forwarded types where you can have one component configuration for multiple services. For example: var container = new WindsorContainer(); container.Register( Component.For<Bar>().Forward<IFoo>() .ImplementedBy<FooBar>()); var foo = container.Resolve<IFoo>(); var bar = container.Resol...

Unit Testing ASP.NET MVC Controllers with Ninject

I recently upgraded Ninject to the most recent builds to fix this issue: ninject binding issue As far as I can tell, it corrected the issue, but it seems to have messed up my controller unit tests. I now get the error that I was trying to fix when running my unit tests. The error is: Error activating ISomething More than one ma...

Ninject.Web.Mvc add-on not working with ASP.NET MVC 2

I'm using the Ninject.Web.Mvc (the MVC 2 version) add-on with ASP.NET MVC 2. This is an excerpt of my Global.asax.cs: protected override void OnApplicationStarted() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes; // RegisterAllControllersIn() is not available in the MVC 2 version of Ninject } protec...

Looking for books on IoC

Hi, I'm having a hard time finding books (eBook or hard copy) on any dependency injection frameworks. I'd really love one on Ninject but I can't seem to find any, not even for the popular Windsor Castle. ...

Asp.Net MVC Ninject and Areas

I have a site that uses Ninject for dependency injection and I have Routing defined within a Bootstrapper class like so: public void RegisterRoutes() { Routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); Routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); Routes.MapRoute( ...

Self binding Membership provider with Ninject

I am trying to self bind MembershipProvider in ASP.NET MVC 2 and then use this binding in an AccountController constructor. This is a snippet from my global.asax.cs // selfbind MembershipProvider in request scope Bind<MembershipProvider>().ToSelf().InRequestScope(); And a snippet from service class: public AccountMembershipService(M...

How many dependencies should be passed using a ctor?

If I have class A which has a dependency on class B, then class B could be passed in to the ctor of class A. What about if class B has a dependency on class C, does that mean class A should receive all required dependencies upon construction ? ...

Ninject binds to the wrong anonymous method when there is more than one method bound type

I am building a framework that I don't want to couple to a particular IOC container so have created a layer on top of Ninject / structuremap etc. I have a binding class that accepts a Func to allow binding to a method. For example public class Binding { public Type Source { get; set; } public Func<object> Method {get; set; } public...

Context variables in Ninject 2

I found this article on Context Variables in an earlier version of Ninject. My question is two-fold. First, how can I get this behavior with Ninject 2? Secondly, do context variables carry through down the request chain? For example, let's say I wanted to replace these calls: var a = new A(new B(new C()))); var specialA = new A(new B(n...

dependency injection with asp.net mvc

I have a service class : public class MyService : IService { private IRepoA repoA; private IRepoB repoB; public MyService(IRepoA repoA,IRepoB repoB) { this.repoA=repoA; this.repoB=repoB; } } my Controller depends on the MyService classL public MyController : DefaultController { IService myServ...