ninject-2

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

Ninject and repository pattern with interfaces

This is the interfaces/class structure I have now: BaseContentObject abstract class public abstract class BaseContentObject : IEquatable<BaseContentObject> { ... } Page concrete class public class Page : BaseContentObject { ... } Repository interface public interface IContentRepository<T> { // common methods for all c...

Avoiding circular dependencies in XNA using Ninject 2.0

I have been using Ninject as the IOC for an XNA project, and was wanting to migrate it to Ninject 2.0. However, XNA is not dependency injection friendly, as certain classes must be instantiated in the constructor of the game class, but must pass the game class to their constructors as well. For example: public MyGame () { this.graph...

Binding singleton to multiple services in Ninject.

Hi, I have a problem which seems very similar to the one described in http://markmail.org/message/6rlrzkgyx3pspmnf which is about the singleton actually creating more than a single instance if you're accessing it using different service types. I'm using the latest release of Ninject 2 for Compact Framework and the exact issue I'm havin...

Ninject Intercept

from what dll can i get the extension of Intercept ? I've added Ninject.Extensions.Interception from http://github.com/danielmarbach/ninject.extensions.interception No luck there. Is there some sample working ? What I need is to make an interceptor that will path through from WcfClient to WcfServer a different functions with different...

Property Injection in Base Controller using Ninject 2

I have the following code in my Global.aspx protected override void OnApplicationStarted() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); RegisterAllControllersIn(Assembly.GetExecutingAssembly()); } protected override IKernel CreateKernel() { return new StandardKernel(new ServiceModule()); } ...

Ninject how to access kernel to create instances?

I am new to ninject using ninject 2.0. My application is hosted in asp.net mvc. Now i don't know how to access kernel created in my class library. I think i should create kernel in global.aspx and load all modules in it. But how can i make it available throughout application? protected void Application_Start() { Regist...

Ninject 2.0: Property Injection without attribute

Is there a way to use Property Injection in Ninject 2 without using the [Inject] attribute? This creates a dependency to Ninject in the class that will be wired using it and I prefer to avoid having unneeded dependencies to my IoC container, that's why I end up using Constructor Injection more often. I guess the same applies to Method I...

Looking for Dependency Injection examples and clear tutorials with Ninject 2.0 for C# ASP.NET (NOT MVC)

I have been searching for a while. I'm not new to dependency injection and have used StructureMap with several projects MVC and the like, but I felt like giving Ninject a go, so as not to miss out on the fun. I am trying to use Ninject with an existing web app which I am bringing up-to-date. I couldn't find on the blogs and wiki provi...

Ninject 2.0 incompatibility with Server 2008 R2?

Hi Everyone. I'm dev'ing an MVC 2 website targeting .NET 4.0 and using Ninject 2.0 (dev box running Win 7 64 pro). All is going well on the dev side, I really enjoyed using Ninject and it works a charm. Until I deploy it to the server. Once I deploy the app to the server (a virtual machine running Win Server 2008 R2 x64, IIS 7.5) the...

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

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

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

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

How to use Ninject2 with WCF?

Hi all, In a short view of the IoC and DI .NET libraries I chose to use Ninject2. According to DDD style in: Infrastructure: I have Entity Framework 4.0 .edmx model and the Repository implementation Domain Layer: I have POCO objects and Repository Interfaces (implemented in Infrastructure) Application Services: I have WCF services tha...

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

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

Ninject V2 InRequestScope: firing constructor on every request

I'm having a hard time with Ninject V2's InRequestScope() for managing a UnitOfWork. _kernel.Bind<UnitOfWork>().To<SqlUnitOfWork>().InRequestScope(); I expect whenever I request the UnitOfWork via the container that the same object is always returned throughout the request. However, in the debugger I have a breakpoint on the object's ...

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