Ninject Auto Register

Auto Register Classes and interfaces for Ninject IoC not by name but by inheritance

So usually when you use Ninject you have to register or bind you classes and interfaces like this

IKernel kernel = new StandardKernel();

kernel.Bind().To();

and this is good but tedious , what if you have big library and you don’t want to bother your self with remembering extra step when you add a new service

and also what if you are introducing Ninject into a project.

so why i think this library is good one thing , it just auto register (Bind)

also it does not depend on a naming convention , it looks for the inheritance and do the binding

Ex:

using (var standardKernel = new Ninject.StandardKernel()) {

NinjectAuto.Register(Contracts.AssemblyInfo.GetExecutingAssembly(), MockServices.AssemblyInfo.GetExecutingAssembly(), standardKernel);

var service = standardKernel.Get();

string writeSomething = service.WriteSomething();

Assert.AreEqual(writeSomething, “Mock Service”);

}

that it , just give where i should find the contracts , where are the implementation and let it do the rest

You can find the source code here

https://github.com/waelemara/NinjectAutoRegister

Also it is available as NuGet Package

https://www.nuget.org/packages/NinjectAutoRegister/

Advertisements

2 thoughts on “Ninject Auto Register

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s