- A console application. My driver program.
- A contracts DLL. My abstracts and interfaces that are known to the driver program.
- A service locator DLL. My services and Factories that will provide my driver program and class libraries everything they need.
- My first class library dll. This is where I would usually put some type of layered architecture or group of assemblies for a new release.
- My second class library dll. This is the same as above but separate from the previous one.
Now here are the references:
1, 4, and 5 reference 2 and 3. (and every dll you ever make after this would reference 2 and 3)
3 references 4 and 5 (and any new dlls you ever make)
Here’s the layout of where all the type definitions are so you can visualize it:
Here’s the driver program code. The test bed for this little experiment:
using System;
using IsolatingTheNinja.Contracts;
using IsolatingTheNinja.Services;
namespace IsolatingTheNinja
{
class Program
{
static void Main(string[] args)
{
ILibrary1Type type1Instance = ServiceLocator.CreateLibrary1Type();
ILibrary2Type type2Instance = ServiceLocator.CreateLibrary2Type();
Console.WriteLine(type1Instance);
Console.WriteLine(type2Instance);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
}
Here’s my Service Locator implementation:
using IsolatingTheNinja.Contracts;
using Ninject;
using Ninject.Modules;
namespace IsolatingTheNinja.Services
{
public class ServiceLocator
{
private static readonly IKernel _kernel = new StandardKernel(new INinjectModule[] { new Library1Module(), new
Library2Module() });
public static ILibrary1Type CreateLibrary1Type()
{
return _kernel.Get<ILibrary1Type>();
}
public static ILibrary2Type CreateLibrary2Type()
{
return _kernel.Get<ILibrary2Type>();
}
}
}
Here’s an example of my module:
using IsolatingTheNinja.Contracts;
using IsolatingTheNinja.Library1;
using Ninject.Modules;
namespace IsolatingTheNinja.Services
{
public class Library1Module : NinjectModule
{
public override void Load()
{
Bind<ILibrary1Type>().To<Library1Type>();
}
}
}
The end result: SUCCESS. Ninject IS Stealthy!
Here’s the Source code