ninject

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. ...

How do I transfer configuration data into injected objects?

I used to use Spring.Net and want to switch to Ninject 1.5 (I have to use .NET2, since some unlucky guy like me still needs to consider users working with win 2k). I used to have everything done in xml and only invoke the container during startup. In this way, only very limited codes are depending on container. I have scenarios like this...

Asp.net Mvc: Ninject - IPrincipal

Hello, I was wondering how I could bind the IPrincipal to HttpContext.Current.User in Asp.net Mvc with Ninject. Friendly greetings, Pickels Edit: Not sure if it matters but I use my own CustomPrincipal class. ...

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...

MVVM && IOC && Sub-ViewModels

I have a ViewModel, it takes two parameters in the constructor that are of the same type: public class CustomerComparerViewModel { public CustomerComparerViewModel(CustomerViewModel customerViewModel1, CustomerViewModel customerViewModel2) { } } public class CustomerViewModel { publ...

How to manage IoC containers in tests?

I'm very new to testing and IoC containers and have two projects: MySite.Website (MVC) MySite.WebsiteTest Currently I have an IoC container in my website. Should I recreate another IoC container for my test? Or is there a way to use the IoC in both? ...

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...

NInject and thread-safety

I am having problems with the following class in a multi-threaded environment: public class Foo { [Inject] public IBar InjectedBar { get; set; } public bool NonInjectedProp { get; set; } public void DoSomething() { /* The following line is causing a null-reference exception */ InjectedBar.DoSomething...

Ninject / NHibernate Events + Observer Pattern

I am trying to implement an observer pattern using ninject and NHibernate. I'd like to be able to inject observers that act as "triggers" when an object is persisted or deleted via NHibernate. Key points- I want the observer to be notified any time an object is persisted, including cascaded saves, which is why I am using NHibernate P...

How to get if the object is already retrieved in inject

Is it possible to know that particular dependency already has been satisfied by ninject kernel? To be clear: Let's suppose we have this module: Bind<IA>().To<A>(); Bind<IB>().To<B>(); And some "client"-code: var a = kernel.Get<IA>(); // how to get here "true" for assumption: "IA was requested (once)" // and "false" for: "IB was not...

How can you inject an asp.net (mvc2) custom membership provider using Ninject?

OK, so I've been working on this for hours. I've found a couple of posts here, but nothing that actually resolves the problem. So, let me try it again... I have an MVC2 app using Ninject and a custom membership provider. If I try and inject the provider using the ctor, I get an error: 'No parameterless constructor defined for this ...

Ninject and DataContext disposal

I'm using Ninject to retrieve my DataContext from the kernel and I was wondering if Ninject automatically disposes the DataContext, or how he handles the dispose() behaviour. From own experiences I know disposing the datacontext is pretty important and that whenever you create a direct object of the DataContext (as in: new DataContext())...

Mocking a datacontext for an object that has a dependancy

Hey everyone, I'm writing some unit tests in my project and I have a datacontext dependancy on the controller containing the methods I'd like to test. I'm using Ninject to inject the dependancy and Moq to create my mock datacontext. My DI makes use of an interface IDataContext which my dbml impliments and is used through out the inject...