We design our apps with design principles and best practices. The resulting apps usually have dependency injection in place already. We then can use Ninject as the dependency injection tool, and set up in-memory test objects along with our production codes.
The question is that how can we click a button to swap the in-memory test environment and debug/release environment easily?
Luckily, there are two features in Visual Studio, build configuration and conditional compilation, which can solve our problem easily.
- In VS solution, create a new build configuration, InMemory, and choose to inherit the setting from Debug.
- Add a constant ‘INMEMORY’ to the ‘Conditional compilation symbols’ in the ‘Build’ tab of project property.
- Add conditional compilation in Ninject’s Register Services code block
/// Load your modules or register your services here!
/// <param name=”kernel”>The kernel.</param>
private static void RegisterServices(IKernel kernel)