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

Cant find NinjectWebCommon in asp.net Web API Project

I am creating an asp.net web api project. I am using Ninject for dependency resolver. I am adding Ninject.Web.WebAPI from nuget. But I don't find any NinjectWebCommon.cs in my App_Start folder Do i need to install any aditional package??
jubair
  • 597
  • 1
  • 6
  • 23
2
votes
0 answers

NullReferenceException when using Portable.Ninject in Xamarin.Mac project

I am unable to use Portable.Ninject in Xamarin.Mac project. I am creating a container like this: public class MainClass { public static StandardKernel Container { get; set; } static void Main(string[] args) { var kernel = new…
Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174
2
votes
2 answers

Does NInject work in medium trust hosting?

I'm doing shared hosting with GoDaddy and I developed a sample ASP.NET MVC app using Castle Windsor and unfortunately, it didn't work in a medium trust setting. Specifically, I got this error: "[SecurityException: That assembly does not allow…
Gabe
  • 5,113
  • 11
  • 55
  • 88
2
votes
1 answer

Ninject 2 + ASP.NET MVC 2 Binding Types from External Assemblies

I'M just trying to get started with Ninject 2 and ASP.NET MVC 2. I have followed this tutorial http://www.craftyfella.com/2010/02/creating-aspnet-mvc-2-controller.html to create a Controller Factory with Ninject and to bind a first abstract to a…
hoetz
  • 2,368
  • 4
  • 26
  • 58
2
votes
1 answer

Ninject: Intercept by attribute without deriving from InterceptAttribute

I'm looking for a way to hook up an interceptor to a method call based on a certain attribute using Ninject. Ninject offers the InterceptAttribute base class to do so which is neat, however I would like to achieve this with a custom attribute. The…
xvdiff
  • 2,179
  • 2
  • 24
  • 47
2
votes
0 answers

Ninject.Web.MVC4 disposes my DbContext exactly once

There are a half dozen identical questions, I know. I've followed the advice of their answers, and I'm still stuck. I've used NuGet to install Ninject.Web.MVC4 and added my bindings to NinjectWebCommon.RegisterServices. I've manually added the…
epalm
  • 4,283
  • 4
  • 43
  • 65
2
votes
1 answer

InRequestScope fails to work in context of ExceptionLogger

I have a custom Web API ExceptionLogger which is added in WebApiConfig like so: config.Services.Add(typeof(IExceptionLogger), new CustomExceptionLogger(kernel.Get()); CustomExceptionLogger is: public class CustomExceptionLogger :…
2
votes
0 answers

Ninject issue with contextual binding and Lazy

Ninject doesn't seem to correctly use WhenInjectedInto contstraint while also using Lazy. Check the following example. The OnLandAttack and the OnLandAttackLazy should each be using the Samurai instance. But the Lazy version ends up with the…
2
votes
2 answers

Ninject and async operations

I have been crawling around on Google a bit now to find any useful examples on how to use Ninject together async/await operations. I have also tried a bit myself to find any pattern that makes this actually work without having to write a lot of…
Rune G
  • 1,447
  • 2
  • 12
  • 26
2
votes
0 answers

OWIN DbContext and a single DbContext for all of my Repositories

I am building a ASP.NET MVC application. I'm new to the whole Repositories/Unit Of Work patterns. I'm part way through implementing a generic repository for my EF objects. I realise that there is an issue with ensuring that you only have a single…
Luke
  • 22,826
  • 31
  • 110
  • 193
2
votes
1 answer

How to use Ninject with XNA?

I'm having difficulty integrating Ninject with XNA. static class Program { /** * The main entry point for the application. */ static void Main(string[] args) { IKernel kernel = new…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
2
votes
1 answer

Can't figure out why Ninject Named Scope isnt working as expected

I have a console application which I wrote a privately constructed Bootstrapper class, exposing a Default property that gives access to the Bootstrapper with only one public method available. I have an issue where the NamedScope that I can not…
tostringtheory
  • 877
  • 8
  • 19
2
votes
2 answers

Ninject - define mapping in web.config file

I'm using Ninject as the IoC container for my ASP.NET MVC app. What I'm currently doing is I have The following layers in my project: Core Factory Infrastructure Logic UI (ASP.NET MVC) Infrastructure, Logic and UI all have references to Core and…
developer82
  • 13,237
  • 21
  • 88
  • 153
2
votes
2 answers

Manage Ninject scope for sessions in a desktop application

We're creating a desktop MVVM application using Prism and Ninject. This application will feature sessions during which data should be recorded under a specific session. Our Views and ViewModels are created by an IoC container by Prism. I would like…
Wouter
  • 2,170
  • 1
  • 28
  • 58
2
votes
0 answers

Ninject with WebAPI and WCF

I'm trying to create an application that will self host several endpoints, some will use WebApi and some other Wcf. The dependencies are registred with Ninject. I'm using the following Nuget packages: Ninject.Extensions.Wcf.SelfHost (for WCF) and…
Bidou
  • 7,378
  • 9
  • 47
  • 70