Ninject IOC
References
Wire Up Bindings
public class Bindings : NinjectModule
{
public override void Load()
{
Bind<IStorageManager>().To<StorageManager>().InSingletonScope();
Bind<IThumbnailGenerator>().To<ThumbnailGenerator>().InSingletonScope();
}
}
Loading Assemblies into the Ninject Kernel
IKernel kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
Use ninject in Console Application
- It's bad practice to use IOC inside a static app, but if you need to use it for a console application, this is how:
- I used this in an azure web job
- You can still use Constuctor Injection with this way as well
public class Program
{
static readonly IKernel Kernel = new StandardKernel();
static void Main()
{
BootStrapIoc();
}
private static void BootStrapIoc()
{
Kernel.Load(Assembly.GetExecutingAssembly());
}
}
Resolve it in a static Method
var thumbnailGenerator = Kernel.Get<IThumbnailGenerator>();