Using Ninject in a plugin like architecture

前端 未结 9 2144
半阙折子戏
半阙折子戏 2020-12-07 10:05

I\'m learning DI, and made my first project recently.

In this project I\'ve implement the repository pattern. I have the interfaces and the concrete implementations.

9条回答
  •  [愿得一人]
    2020-12-07 10:28

    Extending on @ungood good answer, which is based on v.2, with v.3 of Ninject (currently on RC3) it could be made even easier. You needn't any IPluginGenerator anymore, just write:

    var kernel = new StandardKernel();
    kernel.Bind(scanner => scanner.FromAssembliesInPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
                                       .SelectAllClasses()
                                       .InheritedFrom()
                                       .BindToAllInterfaces());
    

    Please note I'm looking for plugins implementing IPlugin (put your interface here) in the same path of the application.

提交回复
热议问题