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();


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


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

Also it is available as NuGet Package


2 thoughts on “Ninject Auto Register

Leave a Reply

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

You are commenting using your 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