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

WCF, async, and a confusion of context

Well, I was going to name this and a question of context, but apparently the word question isn't allowed in titles. Anyway, here's the issue: I use IErrorHandler in my WCF services in order to provide logging without cluttering up all of my service…
zimdanen
  • 5,508
  • 7
  • 44
  • 89
2
votes
2 answers

How to change the scope of an existing binding in Ninject

In one module, I have a binding set up for an object. There are two other modules: a testing module and a web module. The web module wants that binding to be in request scope, and the testing module wants that binding to be in singleton scope. …
cidthecoatrack
  • 1,441
  • 2
  • 18
  • 32
2
votes
1 answer

How do I bind an Interface to automapper using Ninject

I want to use DI whenever I call automapper so that I can uncouple some of my layers. Instead of calling automapper like this: public class MyController : Controller { public ActionResult MyAction(MyModel model) { var…
Robert
  • 4,306
  • 11
  • 45
  • 95
2
votes
0 answers

Register Generic Type in StructureMap Based On Concrete Type

This is very similar to my question about Unity, only it applies to StructureMap instead. I'm trying to emulate a behavior that I can configure in Ninject, only using Unity instead. I am attempting to use the Cached Repository Pattern, given the…
Doctor Blue
  • 3,769
  • 6
  • 40
  • 63
2
votes
2 answers

Isolating a dependency for an instance (and that instances dependencies) when instance created through a Factory

EDIT: I've cleaned this question up significantly after solving my problem, including changing the title. I have a MessageChannel interface which defines (unsurprisingly) a channel that my classes can use to push messages to the end user. Normally…
Todd Bowles
  • 1,554
  • 15
  • 24
2
votes
1 answer

Fluent Validation w/ MVC 5 using Ninject

Do I need to add "AssemblyScanner.FindValidatorsInAssemblyContaining" for every object validator I create? Is there a simpler way? public class FluentValidatorModule : NinjectModule { public override void Load() { …
RiceRiceBaby
  • 1,546
  • 4
  • 16
  • 30
2
votes
1 answer

Does the inbuilt Ninject assembly loaders have error handling

I've written a plugin manager so public class WeinCadPluginManager : NinjectModule, IEnableSerilog { public override void Load() { var codeBaseUrl = new Uri(Assembly.GetExecutingAssembly().CodeBase); var codeBasePath =…
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
2
votes
1 answer

Ninject Inject Common DbContext Into Numerous Repositories

There’s something which I am doing that is working, but I think it can probably be done a lot better (and therefore, with more maintainability). I am using Ninject to inject various things into a controller. The problem which I needed to solve is…
onefootswill
  • 3,707
  • 6
  • 47
  • 101
2
votes
1 answer

Ninject Error with multiple bindings

I have an MVC4 app that uses reflection to load controllers at run time. These controllers as well as the main app use Ninject to inject things into the constructors. Each dynamic controller maintains a list of all the bindings it needs and stores…
2
votes
1 answer

Ninject in non MVC app

I would like to use Ninject in a console app. I have several assemblies and want to be able to use ninject in all of them. I have created resolver project which contains all of my ninject modules I also have a class in here that loads all of my…
TJF
  • 1,081
  • 1
  • 12
  • 26
2
votes
0 answers

MVC4 + Ninject + Quartz - what is the proper way to do the following:

In my solution, I use EF with repository pattern and Ninject inside my main web project to resolve controller dependencies, I also have a Job project that manages Quartz jobs - what is the proper way to link Ninject with Quartz so that EF will…
user2384366
  • 1,034
  • 2
  • 12
  • 28
2
votes
2 answers

Using IoC container in a multi-site environment

I am setting up a architecture for a new project. For this project we are using Sitecore 7 CMS. As you may know, Sitecore supports a multi-site environement. This means that 1 IIS instance can be used for multiple sites because Sitecore resolves…
2
votes
2 answers

Ninject how to resolve dependency in one call

I'm new to Ninject, after do some research, I came up with an example: public interface IWeapon { void Hit(Target target); } public class Sword : IWeapon { public void Hit(Target target) { //do something here } } public…
Doan Cuong
  • 2,594
  • 4
  • 22
  • 39
2
votes
1 answer

Conditional dependency injection binding only when property not null

It is a desktop application which is obliged to impersonate the current user when accessing the underlying data source. How can I tell Ninject not to bind the dependency until the property of a parent object is not null? Application forces user…
2
votes
1 answer

RoleProvider injection with Ninject

First off I want to say there is a ton of answers on SO and google searches surrounding this, however I'm running into an issue that prevents those solutions from working. The answer here seems to be the way to go.…
The Muffin Man
  • 19,585
  • 30
  • 119
  • 191
1 2 3
99
100