1

Is there any method built-in to Ninject which allows for dynamic instantiation of any given type given its assembly-qualified name (without the need to bind the types manually in a custom NinjectModule)?

I could of course use Activator.CreateInstance but since I am already using Ninject I would prefer sticking to it rather than using this method (which I heard may be pretty slow, by the way).

DotNetStudent
  • 889
  • 9
  • 24
  • 1
    Is this of any use? http://stackoverflow.com/questions/2227548/creating-an-instance-using-ninject-with-additional-parameters-in-the-constructor – Polynomial Oct 05 '11 at 13:05

2 Answers2

2

You could use below, which will look for all classes which extend NinjectModule in a given assembly and load them:

var kernel = new StandardKernel();
kernel.Load(Assembly.Load("assembly.dll"));
Teoman Soygul
  • 25,584
  • 6
  • 69
  • 80
2

Ninject needs to have bindings to create instances. These bindings can either be created statically or using conventions. Depending on what you want to do, conventions might be what you need. Have a look at Ninject.Extensions.Conventions.

Remo Gloor
  • 32,665
  • 4
  • 68
  • 98