Using Ninject in a plugin like architecture

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

    you can easily do it with normal C# reflection, you don't need any extra technology.

    There are quite a few examples on the web, e.g. http://www.codeproject.com/KB/cs/c__plugin_architecture.aspx

    In general in your main application, you need to load the assembly implementing the plugin, e.g.:

    ass = Assembly.Load(name);
    

    and then you need to create an instance of your plugin. If you know the name of the class it would look like this:

    ObjType = ass.GetType(typename);
    IPlugin plugin = (IPlugin)Activator.CreateInstance(ObjType);
    

    and then you just use it.

提交回复
热议问题