EDIT: I forgot to move the kernel to the parent class without generation and provide a virtual method to access it. I understand that the example below, as is, would create many instances of the kernel.
I just found out how to give an injection last week, and here is how I set up now:
using Ninject; using System.Reflection; namespace Infrastructure { public static class Inject<T> { static bool b = Bootstrap(); static IKernel kernel; static bool Bootstrap() { kernel = new StandardKernel(); kernel.Load(Assembly.GetExecutingAssembly()); return true; } public static T New() { return kernel.Get<T>(); } } }
And then I plan to make the various ninject module classes part of the Infrastructure namespace to load them.
I have not been able to find anything here or Google that provides examples of how to actually organize the use of Ninject in your project, but this seems right to me, as it allows me to use only the Ninject link in this assembly. Is this more or less the βrightβ way or is there a better design?
source share