vendredi 11 août 2017

Improve my NinjectBootstrapper static class.

A NinjectBootstrapper class has been created in a Service project(responsible for getting products). This is my code

public static class NinjectBootstrapper
{
   private static readonly object _thislock = new object();

   //flag to prevent bootstrap for executing multiple times
   private static bool _done;

   public static void Bootstrap()
  {
     lock(_thislock)
     {
        if(_done)
        {
           return;
        }
        _done = true;

       // services
       NinjectContainer.Kernel.Bind<IProductService>().To<ProductService>();
       // repositories
       NinjectContainer.Kernel.Bind<IProductRepository>().To<ProductRepository>();
     }

  }

}

Now, while this works, I would really like to know if there are better ways to refactor my code. For instance I've read a lot of stuff about using a singleton instead of the static class. I'd like to really set a good base here to make it easy and flexible for future developers to extend functionality. What are some good pointers and tips I can take into consideration?

Aucun commentaire:

Enregistrer un commentaire