ninject

Injecting AutoMapper dependencies using Ninject

I am having trouble injecting AutoMapper into an ASP.NET MVC 2 application using Ninject. I used Jimmy Bogard's post on AutoMapper and StructureMap type Configuration as a guide. public class AutoMapperModule : NinjectModule { public override void Load() { Bind<ITypeMapFactory>().To<TypeMapFactory>(); Bind<Config...

Injecting HttpContext in Ninject 2

In my asp.net mvc application I'm using Ninject as a DI framework. My HttpAccountService is used by my controllers to get info from and to cookies. For this I need the HttpContext.Current in the HttpAccountService. As this is a dependency I injected it throught the constructor as such: kernel.Bind<IAccountService>() .To<HttpAccount...

HttpHandler Property Injection using Ninject returning null

I have the following httphandler: public class NewHandler : IHttpHandler { [Inject] public IFile FileReader { get; set; } public NewHandler() { } public void ProcessRequest(System.Web.HttpContext context) { .... var something = SomeMethod(FileReader); .... ...

Ninject 2.0: Passing different parameters depending on implementation

Hi everybody, I have just started to work with Ninject 2.0 with ASP.NET MVC 2. So, I have an interface IMongoRepository and class MongoRepository. MongoRepository receives a parameter string collection. Depending on the collection I want to use, I pass in a different value in parameter for MongoRepository. I hope I am phrasing this co...

How to add new object to track in Ninject after Application_Started?

Is it possible to add a new object that Ninject should be responsible for (lifetime, injection etc.) in an ASP.NET application after the Application_Started event is fired? My application needs to dynamically designate objects that should be tracked well after the application is started ...

How to instantiate a MEF exported object using Ninject?

My application is using MEF to export some classes from an external assembly. These classes are setup for constructor injection. The issue I am facing is that MEF is attempting to instantiate the classes when I try to access them. Is there a way to have Ninject take care of the instantiation of the class? IEnumerable<Lazy<IMyInterface>...

Dependency Inject with Ninject 2.0

A little question regarding Ninject. I use a WCF 'duplex channel' to communicate with a service. The channel is defined as an interface, lets call it IMyChannel for simplicity. To instantiate a channel we use DuplexChannelFactory<IMyChannel> object's CreateChannel() method. So far I have manage to bind the factory class with this. Bin...

How to use Ninject in constructor injection of a type in an external assembly

I am loading a type from an external assembly and want to create an instance of the type. However, this type/class is setup for constructor injection by objects currently being managed/bound by Ninject. How can I use Ninject to create an instance of this type and inject any constructor dependencies? Below is how I get this type. Assem...

In Ninject 2.0, how do I have both a general binding and a binding for a specfic case?

I have a situation where I want to dependency inject my user object, but also place the current user in the IoC container. I want the following lines to work: kernel.Get<User>(); // Should return a new User() kernel.Get<User>("Current"); // Should return the current user One might think bindings like this would work: Bind<User>().To...

Ninject syntax for "Bind" with multiple arguments

How I can use multiple parameters in Ninject syntax like following? Bind<IMyRepository>() .To<SqlMyRepository>() .WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString ); What if more than one parameter need to be passed? ...

Basic Ninject Information required please.

I've been slowly teaching myself the fundamentals of interface driven programming and I'm struggling to get my head round a few principles regarding inversion of control specifically with Ninject. Lets say I have a concrete model class as follows... public sealed class Host : EntityAuditable<Host, Guid> I have a base class which def...

WCF with Ninject throwing ArgumentNullException

I am new to Ninject and trying to evaluate how well it compares to Windsor Castle, which I am more familiar with. My application is a WCF service application hosted in IIS. As a result, I am trying to spin-up the container/kernel and use the NinjectServiceHostFactory to create my service class, etc. Unfortunately, I'm getting an Argum...

How to use custom injection attribute for properties when using StructureMap?

I would like to have my own injection attribute so that I am not coupling my code to a particular IOC framework. I have a custom injection attribute that my code uses to denote that a property should be injected. public class CustomInjectAttribute : Attribute {} Fictitious example below... public class Robot : IRobot { [CustomInje...

Problems with ASP.NET Session State / NInject / OnePerRequest behavior

This is quite a lengthy post, so bear with me. I'm not sure whether it is primarily about ASP.NET Session State behaviour, NInject, application design, or refactoring. Read on and then you can decide... :-) Background First, a bit of background. We are working on trying to refactor a large webshop into a more maintainable , structu...

Ninject, Providers and Activator.CreateInstance

I'm fairly new to Ninject, but I have successfully managed to use it for DI using a custom provider. The binding is initialised as follows kernel = new StandardKernel(); kernel.Bind<IPatientRecordLocator>().ToProvider<PatientRecordLocatorProvider>(); and in the custom provider I call Activator.CreateInstance like so protected over...

How do I use Common Service Locator in Ninject 2

Changes in Ninject 2 say that Ninject support Common Service Locator, but how do I use it? I don't find any manual or sample. ...

ninject mvc and wcf

Ninject has extentions for mvc and wcf but in our case mvc application is hosting wcf as well. How do u go about using both, looks like both extention provides base class for httpapplication(global.aspx), What is the correct way of using it? At this moment looks like i need to grab pieces out of wcf extention and put it in mvc extenti...

How to list all registered IBindings in Ninject?

I see methods for enumerating lists of bindings for a given service (type), but nowhere do I find a method returning a list of everything that's been bound in my loaded modules. I'm looking for something like Kernel::IEnumerable<IBinding> GetAllRegisteredBindings() Does this exist? If not, might I be able to build an extension that cou...

Using Dependency Injection with Http Handlers

I am using ASP.NET MVC 2 with Ninject, and Linq2SQL behind a repository pattern, based on Rob Conery's TekPub Starter Site. With controllers it all works fine, however I have an HTTP Handler (it serves and resizes images from a DB), and I have no idea how I use Ninject to replace my ISession interface with a concrete instance of my Linq...

Why to use a IoC framework

Hi, I've been reading about Inversion of Control frameworks and I'm just playing around with the question: "Why in the hell do I need a framework to do this?" Don't misunderstood my question... the pattern is something we programmers use often but... a full featured framework to do that? I must be missing something and that's the reaso...