Initializer RRS feed

  • Question

  • Hello,

    I created a ContextInitializer class:

    MyContextInitializer : IDatabaseInitializer<MyContext>

    I want the inicializer to run ONLY when I run a test.

    I don't want the initializer to run on build.

    I want to be safe that the initializer does not run on the server.

    What should I do?

    Thank You,



    Friday, November 4, 2011 1:07 PM


  • Hi,

    just make sure you set the correct initializer on startup.

    The way you select the initializer is your decision. you could use a configuration entry. or if you are using a DI container, you could set up a different DI container configuration for test and productive scenarios. you might encapsulate the SetInitializer in an interface.

    Something like

    class ProductiveInitializer : IInitializer

    class TestInitalizer : IInitializer

    Decide with a configuration wich instance you wanna use (or wich implementation you want to use for setting up the DI container).

    if (RunningInTestEnv) ...




    Sunday, November 6, 2011 11:49 AM