Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What DLL is the Bind(Of T) from Ninject located in

I am using .Net 3.5 and a console application that eventually will become a windows service.

Most of the examples I find use something like

Bind<IWeapon>().To<Sword>();

I have included all the DLL as references in my project and I the compiler is still complaining. Any clues of where I am going wrong? Sorry this might be a stupid question.

UPDATE: Just notice a whole lot of other libraries that seem to be needed but aren't referenced. There are libraries like Castle Core. Should these be included?

like image 220
uriDium Avatar asked Feb 23 '10 13:02

uriDium


People also ask

What is ninject DLL?

Ninject helps you use the technique of dependency injection to break your applications into loosely-coupled, highly-cohesive components, and then glue them back together in a flexible manner.

What is ninject C#?

NInject is a popular IOC container that can be used to inject dependencies in your WebAPI controllers easily. IDG. Dependency injection is a software design pattern that helps you to build pluggable implementations in your application using loosely coupled, testable components.

Is Ninject open source?

License. Ninject is intended to be used in both open-source and commercial environments.


1 Answers

The first thing you need to be sure you're doing is executing your binding code within a Ninject module inside of the Load method, which you override.

For example:

public class ApplicationModule : NinjectModule {

  public override void Load() {

    Bind<IWeapon>().To<Sword>(); 

    // additional bindings continue ...
  }
}

The NinjectModule class inherits classes and interfaces that define the Ninject fluent binding syntax thus making the Bind<T>() method available within the scope of the class. These modules are then passed to the Ninject kernel when the kernel is instantiated:

var kernel = new StandardKernel(new ApplicationModule()); 

The Load() method of each module passed to the kernel will then be called and the binding definitions contained within the methods executed.

The example above specifies NinjectModule as the base class; however, this is specific to version 2.0 of Ninject. If you are using Ninject 1.x, your base class will be StandardModule. In either case, the load method is overriden and binding statements (which are similar in both versions) are issued there.

To further answer your question:

  • For Ninject 1.x, the required DLL is ninject.core.dll and the namespace that StandardModule is defined in is Ninject.Core.

  • For Ninhect 2.0, the required DLL is ninject.dll and the the namespace that NinjectModule is defined in is Ninject.Modules.

In both cases, you may need to reference more namespaces depending on how complex your binding statements get -- i.e. if you use contextual bindings or scope your bindings, etc. In the case of Ninject 1.x, you also may need to reference Ninject.Conditions.dll for these more complex cases.

You do not need to reference Castle.Core unless you are using Ninject's interception feature -- which is a 1.x core feature but an extension in version 2.0.

Hope this helps.

like image 99
Peter Meyer Avatar answered Sep 29 '22 06:09

Peter Meyer