ninject-2

Contextual bindings with Ninject 2.0

In Ninject 1.0 I had following binding definitions: Bind<ITarget>().To<Target1>().Only(When.Context.Variable("variable").EqualTo(true)); Bind<ITarget>().To<Target2>(); Given such bindings I had calls: ITarget target = kernel.Get<ITarget>(With.Parameters.ContextVariable("variable", true)); ITarget target = kernel.Get<ITarget>(With.Par...

Using ASP.NET MVC 2 with Ninject 2 from scratch

I just did File -> New Project last night on a new project. Ah, the smell of green fields. I am using the just released ASP.NET MVC 2 (i.e. no preview or release candidate, the real thing), and thought I'd get off to a good start using Ninject 2 (also released version) with the MVC extensions. I downloaded the MVC extensions projec...

This 404 seems unavoidable - what am I doing wrong? [Ninject 2.0 with ASP.NET MVC 2 on .NET 4]

I downloaded the fairly new Ninject 2.0 and Ninject.Web.Mvc (targeting mvc2) sources today, and successfully built them against .NET 4 (release configuration). When trying to run an application using Ninject 2.0, i keep getting 404 errors and I can't figure out why. This is my global.asax.cs (slightly shortified, for brevity): using .....

Ninject giving NullReferenceException

I'm using asp.net MVC 2 and Ninject 2. The setup is very simple. Controller calls service that calls repository. In my controller I use inject to instantiate the service classes with no problem. But the service classes don't instantiate the repositories, giving me NullReferenceException. public class BaseController : Controller { ...

Binding an interface to 2 different concrete objects in ninject based on the method attribute

I have 2 different concrete objects, lets save ConcreteOne and ConcreteTwo. Each of these implement an interface ILooseyGoosey. I would like ninject to call a different method depending on the attribute on that method. This is what I have so far: public class ConcreteOne : ILooseyGoosey { public void SomeMethod() { }; } public class ...

Ninject 2 + ASP.NET MVC 2 Binding Types from External Assemblies

Hi, I'M just trying to get started with Ninject 2 and ASP.NET MVC 2. I have followed this tutorial http://www.craftyfella.com/2010/02/creating-aspnet-mvc-2-controller.html to create a Controller Factory with Ninject and to bind a first abstract to a concrete implementation. Now I want to load a repository type from another assembly (wher...

Can Ninject be instructed to apply context-based logic to all bindings?

We've begun using Dependency Injection recently, and we've chosen Ninject 2 (for now) as our IoC Container. As I refactor our solution to incorporate DI principles, I've run into something that bugs me a little, and I'm wondering if there's an easy way to get around it. For our data layer, we have a whole bunch of data-access classes t...

Why can't I inject value null with Ninjects ConstructorArgument?

When using Ninjects ConstructorArgument you can specify the exact value to inject to specific parameters. Why can't this value be null, or how can I make it work? Maybe it's not something you'd like to do, but I want to use it in my unit tests.. Example: public class Ninja { private readonly IWeapon _weapon; public Ninja(IWeapo...

Ninject Kernel Scope

I'm new to Ninject, and I was wondering if the scope of the kernel should be 1 per application. So should I treat the kernel as a singleton? Thanks. ...

Deploying MVC2 application to IIS7.5 - Ninject asked to provide controllers for content files

I have an application that started life as an MVC (1.0) app in Visual Studio 2008 Sp1 with a bunch of Silverlight 3 projects as part of the site. Nothing fancy at all. Using Ninject for dependency injection (first version 2 beta, now the released version 2 with the MVC extensions). With the release of .Net 4.0, VS2010, MVC2 etc., we dec...

How do I get property injection working in Ninject for a ValidationAttribute in MVC?

I have a validation attribute set up where I need to hit the database to accomplish the validation. I tried setting up property injection the same way I do elsewhere in the project but it's not working. What step am I missing? public class ApplicationIDValidAttribute : ValidationAttribute { [Inject] protected IRepository<MyTyp...

Dependency Injection with Custom Membership Provider

I have an ASP.NET MVC web application that implements a custom membership provider. The custom membership provider takes a UserRepository to its constructor that provides an interface between the membership provider and NHibernate. The UserRepository is provided by the Ninject IoC container. Obviously, however, this doesn't work whe...

Asp.net Mvc - Kigg: Maintain User object in HttpContext.Items between requests.

first I want to say that I hope this doesn't look like I am lazy but I have some trouble understanding a piece of code from the following project. http://kigg.codeplex.com/ I was going through the source code and I noticed something that would be usefull for my own little project I am making. In their BaseController they have the follo...

How to inject ninject itself into a static class with extension functions.

I got some static classes with extension methods which add 'business logic' to entities using the repository pattern. Now sometimes i need to create a new IRepository in these extension functions. I'm currently working around it by accessing my Ninject kernel through the object I'm extending, but it's really ugly: public static IEnume...

Ninject: Abstract Class

Do I need to do something different in an abstract class to get dependency injection working with Ninject? I have a base controller with the following code: public abstract class BaseController : Controller { public IAccountRepository AccountRepository { get; set; } } My module looks like this: public cla...

Ninject: Shared DI/IoC container

I want to share the container across various layers in my application. I started creating a static class which initialises the container and register types in the container. public class GeneralDIModule : NinjectModule { public override void Load() { Bind<IDataBroker>().To<DataBroker>().InSingletonScope(); } } publi...

What is the best way to reset Ninject's IKernel container in an MVC app?

Basically in my Global.asax code I have the following IKernel property for Ninject setup like this (Also taking advantage of Microsoft.Practices.ServiceLocation). This Container is automatically called upon once it seems on the CreateKernel() override: protected override IKernel CreateKernel() { return Container; ...

Ninject: Dynamically loading modules in Silverlight

The reason I want to load modules dynamically is to avoid circular dependency issue. I have following layers View --> ViewModel --> DataProvider --> ServiceClient (wcf proxies). Now I want a static IoC container that can be shared across these layers. I want to make my View testable and to do that I’ll have to inject the various depende...

Should I create an interface for each Model?

Hey everyone I'm just getting started with Dependency Injection (DI) using Ninject and am working through my controllers looking to decouple them from my models a bit more. At the moment, inside of my controllers I am creating an instance of some given model e.g: var activitiesModel = new ActivitiesModel(); For each of my models tha...

Injecting a dependancy into a base class

Hey everyone, I'm on a roll today with questions. I'm starting out with Dependency Injection and am having some trouble injecting a dependency into a base class. I have a BaseController controller which my other controllers inherit from. Inside of this base controller I do a number of checks such as determining if the user has the rig...