Using Ninject in a plugin like architecture

前端 未结 9 2105
半阙折子戏
半阙折子戏 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:38

    I got this as a hit for Activator.CreateInstance + Ninject and just wanted to point out something in this area - hopefully it will inspire someone to come up with a real killer answer to this question on SO.

    If you havent yet gone to the trouble of auto-scanning Modules and classes and registering them with Ninject properly, and are still creating your plugin via Activator.CreateInstance, then you can post-CreateInstance inject the dependencies in via

    IKernel k = ...
    var o = Activator.CreateInstance(...);
    k.Inject( o );
    

    Of course, this would only be a temporary solution on the way to something like http://groups.google.com/group/ninject/browse_thread/thread/880ae2d14660b33c

提交回复
热议问题