• Is Ninject 2 Stealthy

    Based on this documentation for Ninject , they claim to be stealthy!

     

    Stating:

    Ninject will not invade your code. You can easily isolate the dependency on Ninject to a single assembly in your project.”

     

    Well, at first I was skeptical and just could not figure it out. So I put on my scientist hat for a little while in an attempt to prove them right!

     

    Here’s what my test bed looked like… a pretty standard project configuration with multiple DLLs

     

      

     

     

    1. A console application. My driver program.
    2. A contracts DLL. My abstracts and interfaces that are known to the driver program.
    3. A service locator DLL. My services and Factories that will provide my driver program and class libraries everything they need.
    4. 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.
    5. 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

     

     

     

     

     

     

     

     

     

     

     

    Full story

    Comments (0)

  • Setting Up Fitnesse for C# .Net

    I use to use cory foy's example, but it's a bit dated now.

     

    Step 1:

    Download fitnesse

    http://fitnesse.org/FrontPage.FitNesseDevelopment.DownLoad

     

    click the fitnesse.jar link

     

    extract it to c:\fitnesse

     

    run java –jar fitnesse.jar –p [port]

    (If you want port 80 then leave off the –p and port)

     

    Navigate to http://localhost/ to try it out or http://localhost:[port]

     

    Step 2:

    Get fitsharp so you have the dlls for making fixtures and slim runner

    go to: http://github.com/jediwhale/fitsharp/downloads

    extract it to c:\fitnesse\slim

     

    Step 3:

    Make your test fixtures class library in visual studio

     

    Step 4:

    reference the fit and fitsharp dlls from c:\fitnesse\slim

    and reference any of your “System under test” dlls. (your dlls that your system uses that you want to test)

     

    Step 5:

    Write a fixture

    using fit;

     

    namespace Fitnesse

    {

        public class CalculateDiscount : ColumnFixture

        {

        }

    }

     

    Step 6:

    Make your first wiki page.

    Such as editing the front page and adding MyFirstFitnessePage

    It will show up like this after you save it:

    MyFirstFitnessePage?

    Click on the ‘?’ to create it.

     

    Step 7: make it a test page

    go to properties and change it to a “test” page.

     

    Step 8: Add all this stuff to the top of it

    !define TEST_SYSTEM {slim}

    !define COMMAND_PATTERN {%m -r

    fitSharp.Slim.Service.Runner,C:\Fitnesse\slim\fitsharp.dll %p}

    !define TEST_RUNNER {C:\Fitnesse\slim\Runner.exe}

    !path C:\projects\Fitnesse\Fitnesse\bin\Debug\Fitnesse.dll

     

    (the last line should be a direct path to your fixtures dll)

     

    Step 9:

    Make a test table

    |!-Fitnesse.CalculateDiscount-!|

    |amount     |discount?    |

    |0          |0             |

    |100        |0             |

    |999        |0             |

    |1000       |0             |

    |1010       |50.5          |

    |1100       |55            |

    |1200       |60            |

    |2000       |1000          |

     

    the !- -! Syntax forces literal text so it won’t interpret “CalculateDiscount” as a wiki page link you’ll get an error like this if you don’t do it

     

    Could not find class CalculateDiscountATitleCreatePageHrefCalculateDiscountEditNonExistentTrueA

     

    Apparently “ATitleCreatePageHrefCalculateDiscountEditNonExistentTrueA” gets appended when the ? is next to it.

     

     

     

    Full story

    Comments (0)