Questions tagged [ninject]

NInject is a dependency injection framework for .NET applications.

Ninject is a lightweight dependency injection framework for .NET applications. It helps you split your application into a collection of loosely-coupled, highly-cohesive pieces, and then glue them back together in a flexible manner. By using Ninject to support your software’s architecture, your code will become easier to write, reuse, test, and modify.

Ninject works with different types of .NET projects including Forms, WPF/Silverlight, WP7 and MVC.

As an example, the MVC implementation allows interfaces (dependencies) to be added to a controller's constructor parameters, and also into Filters. Ninject uses a library WebActivator for .NET to inject specified implementations into the constructors at the right time.

Installation

Installing Ninject can most easily be done using its NuGet package:

Install-Package ninject
3869 questions
2
votes
1 answer

Solving a cyclical dependency in Ninject (Compact Framework)

I'm trying to use Ninject for dependency injection in my MVP application. However, I have a problem because I have two types that depend on each other, thus creating a cyclic dependency. At first, I understand that it was a problem, because I had…
Alex
  • 3,429
  • 4
  • 36
  • 66
2
votes
1 answer

Property inject in unittest with ninject

I have a simple contoller of a standard MVC 5 web application. I installed the MVC 5 Ninject nuget package. I created a constructor and the interface that I have defined is injected. If I create a public property this is also injected. Now when I…
LockTar
  • 5,364
  • 3
  • 46
  • 72
2
votes
1 answer

How to properly use Ninject's NamedScope extension?

I have a pattern that comes up all the time when I'm working. I am almost exclusively a web developer, and Ninject's InRequestScope handles 99% of my needs. Here's the pattern: // abstractions interface IFoo { void FooMe(); int…
Bryan Slatner
  • 1,588
  • 2
  • 16
  • 19
2
votes
1 answer

Project dependencies using Ninject

Continuing my studies in Dependency Injection, I have some doubt about the relationship between some projects and their dependencies. I created the IocConfig class in App_Start folder IocConfig class public class IocConfig { public static void…
Lucas_Santos
  • 4,638
  • 17
  • 71
  • 118
2
votes
1 answer

Ninject.MVC WebViewPage _Layout.cshtml Injections are Null

I am Using Ninject.MVC4 in my ASP.NET MVC4 Project and I am setting Up my Bindings in the created "NinjectWebCommon.cs" file. I've overwritten the Default View, to Inject an Permissionmanager for my Views public abstract class…
squadwuschel
  • 3,328
  • 3
  • 34
  • 45
2
votes
0 answers

NInject a default binding with overrides

The code I have is... public interface IEntityA : IGenericEntity { ... } public interface IEntityB : IGenericEntity { ... } .... public interface IEntityZ : IGenericEntity { ... } public class EntityComparer : IEqualityComparer where T :…
Mick
  • 6,527
  • 4
  • 52
  • 67
2
votes
2 answers

asp.net MVC 4 Ninject OnApplicationStarted()

Hello Im learning the basics of asp.net by making simple blog with this tutorial http://www.prideparrot.com/blog/archive/2012/12/how_to_create_a_simple_blog_part1#story1-configure-ninject-mvc And when I want to configure Ninject for MVC project in…
Matthew Jaeger
  • 59
  • 1
  • 11
2
votes
2 answers

Injection of class with multiple constructors

Resolving a class that has multiple constructors with NInject doesn't seem to work. public class Class1 : IClass { public Class1(int param) {...} public Class1(int param2, string param3) { .. } } the following doesn’t seem to work: IClass1 instance…
Jax
  • 21
  • 1
  • 2
2
votes
0 answers

Ninject form injection and Cannot access a disposed object

I have Set Form, inside this form I inject some another set form public partial class ServicePriceBlockSetForm : RibbonForm { [Inject] private OtherServiceSetForm OtherServiceSetForm { get; set; } public…
2
votes
2 answers

Open Generics and IEnumerable with Ninject

I have the following interface... public interface IHandler where TFor : IRequest { void Handle(IEnumerable requests); } which is typically implemented like so... public class AssignmentHandler : HandlerBase,…
Baldy
  • 3,621
  • 4
  • 38
  • 60
2
votes
1 answer

How to bind decorators with Ninject from outside in?

I use ninject bindings with WhenInjectedInto<> to bind decorators from inside out. However, from different entry points I need different features, maybe run in different sequence, so I would like to bind the decorators chain from outside in. Is this…
zafeiris.m
  • 4,339
  • 5
  • 28
  • 41
2
votes
1 answer

Stop Ninject from binding Func automatically

I have a PriorityQueue that takes a Func as construction parameter. public PriorityQueue(ISomeOtherInjectedThing other, Func cmp_func) {...} I bound this using Ninject: Bind(typeof (IPriorityQueue<,>)).To(typeof(PriorityQueue<,>)); We…
Wilbert
  • 7,251
  • 6
  • 51
  • 91
2
votes
1 answer

Ninject Implicit constructor binding error for generic collections

Consider the following code: using System.Collections.ObjectModel; using Ninject; namespace ConsoleApplication2 { public interface IComponent { //stuff } public class Component : IComponent { // implementation of stuff } public…
therealjumbo
  • 1,079
  • 1
  • 10
  • 14
2
votes
1 answer

Ninject Error using configuration manager while registering. This method cannot be called during the application's pre-start initialization phase

I have a C# 4.0 Mvc 4 web application that uses Ninject. Everything has been registering fine, but when i try to access values from my Web.config section using configurationmanager class i get this error: "An error occurred creating the…
rleffler
  • 430
  • 6
  • 15
2
votes
1 answer

ASP.Net MVC 5 + SignalR + Ninject

What is the best practice way for to wire up Ninject with both MVC5 and SignalR? Ninject recommends having Global.asax inherit NinjectHttpApplication and implementing a CreateKernal method: //Global.asax ([Ninject MVC Website…
James
  • 7,877
  • 7
  • 42
  • 57
1 2 3
99
100