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
33
votes
1 answer

Guidelines For Dispose() and Ninject

So, I have a method exposed from a WCF service as such: public GetAllCommentsResponse GetAllComments(GetAllCommentsRequest request) { var response = new GetAllCommentsResponse(); using(_unitOfWork) try { …
Nate222
  • 856
  • 2
  • 15
  • 25
32
votes
1 answer

What's the difference between .ToConstructor and .ToMethod in Ninject 3?

In Ninject3 there's a new .ToConstructor feature. As described, it helps to strongly-type constructor arguments like: Bind().ToConstructor( ctorArg => new MyService(ctorArg.Inject(), ctorArg.Inject())); What's actually…
Shaddix
  • 5,901
  • 8
  • 45
  • 86
32
votes
2 answers

Validation: How to inject A Model State wrapper with Ninject?

I was looking at this tutorial http://asp-umb.neudesic.com/mvc/tutorials/validating-with-a-service-layer--cs on how to wrap my validation data around a wrapper. I would like to use dependency inject though. I am using ninject 2.0 namespace…
chobo2
  • 83,322
  • 195
  • 530
  • 832
32
votes
10 answers

NinjectDependencyResolver fails binding ModelValidatorProvider

I'm developing an ASP.NET Web Api 2.2 with C#, .NET Framework 4.5.1. After updating my Web.Api to Ninject 3.2.0 I get this error: Error activating ModelValidatorProvider using binding from ModelValidatorProvider to…
VansFannel
  • 45,055
  • 107
  • 359
  • 626
31
votes
4 answers

Making Entity framework implement an interface

I want to use IoC with Entity framework and Ninject. I figure I need the Generated Entity classes to implement an interface, ICRUD. There's a walkthrough that shows how to force Entity framework to implement an interface. I followed the…
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
31
votes
5 answers

Error "More than one matching bindings are available" when using Ninject.Web.Mvc 2.0 and ASP.NET MVC 1.0

Recently I've switched to Ninject 2.0 release and started getting the following error: Error occured: Error activating SomeController More than one matching bindings are available. Activation path: 1) Request for SomeController Suggestions: 1)…
Denis Parchenko
  • 665
  • 1
  • 6
  • 18
30
votes
2 answers

NInject: how to pass parameters when Get()?

I'm using the attached image to explain what I meant. I have a few classes managed by NInject. Some of them have a few singleton instances, and others are in transient scope. In the image, blue rectangles are singltons, red are transient. The…
Zach
  • 5,715
  • 12
  • 47
  • 62
29
votes
3 answers

Ninject.ActivationException thrown only on first web request (WebAPI 2, OWIN 3, Ninject 3)

I am attempting to create a "barebones" Web API project that uses OWIN middleware, Ninject Depencency Injection, and ultimately to be hosted in IIS. I have followed instructions found in an article, "Befriending ASP.NET Web.API2, OWIN and Ninject,"…
Jon Pawley
  • 467
  • 1
  • 6
  • 13
28
votes
4 answers

IOC - Should util classes with static helper methods be wired up with IOC?

Just trying to still get my head around IOC principles. Q1: Static Methods - Should util classes with static helper methods be wired up with IOC? For example if I have a HttpUtils class with a number of static methods, should I be trying to pass it…
Greg
  • 34,042
  • 79
  • 253
  • 454
27
votes
9 answers

Using Ninject in a plugin like architecture

I'm learning DI, and made my first project recently. In this project I've implement the repository pattern. I have the interfaces and the concrete implementations. I wonder if is possible to build the implementation of my interfaces as "plugins",…
user32415
  • 466
  • 1
  • 5
  • 6
26
votes
10 answers

Ninject error in WebAPI 2.1 - Make sure that the controller has a parameterless public constructor

I have the following packages and their dependencies installed in my WebAPI project: Ninject.Web.WebApi Ninject.Web.WebApi.OwinHost I am running this purely as a web-api project. No MVC. When I run my application and send a POST to the…
Hades
  • 1,975
  • 1
  • 23
  • 39
26
votes
1 answer

Issue using ASP.Net MVC 4 Web API with Ninject.Web.WebApi

I'm trying to use the new ASP.Net MVC 4 Web API project template with Ninject but have hit a wall on the following error: Method 'GetFilters' in type 'Ninject.Web.WebApi.Filter.DefaultFilterProvider' from assembly 'Ninject.Web.WebApi,…
mmacneil007
  • 578
  • 1
  • 8
  • 20
26
votes
3 answers

How do I work with Ninject in an ASP.NET MVC Web App?

I've created a new MVC Web application and I have references to Ninject.dll, Ninject.Web.Common.dll and Ninject.Web.MVC.dll. Global.asax.cs: public class MvcApplication : NinjectHttpApplication { public static void…
Mediator
  • 14,951
  • 35
  • 113
  • 191
25
votes
5 answers

Structuremap, AutoFac, or Ninject, which one is great for a large scale web app?

I have some experience in working by Structuremap. And now I'm creating a big and large scale web app (really a social networking site) using ASP.NET MVC 3, Entity Framework 4.1 code-first, SqlServer 2008, via C#.NET 4. Which one of Structuremap,…
amiry jd
  • 27,021
  • 30
  • 116
  • 215
25
votes
7 answers

Using Ninject to fill Log4Net Dependency

I use Ninject as a DI Container in my application. In order to loosely couple to my logging library, I use an interface like this: public interface ILogger { void Debug(string message); void Debug(string message, Exception…
Brook
  • 5,949
  • 3
  • 31
  • 45