Search code examples
.netdependency-injectionframeworksninjectkephas

Kephas evaluation for Dependency Injection.


When evaluating Kephas, I’ve seen that it uses then Managed Extensibility Framework from Microsoft (System.Composition package). However, we use Ninject for Dependency Injection. Am I forced into changing the DI container, or may I use Ninject?


Solution

  • You don't have to change anything about your DI framework you use, in this case Ninject. However, depending on your migration strategy, you have to consider the following:

    • Kephas uses a DI abstraction which can run theoretically on any concrete DI implementation, so technically speaking you could use under the hood your Ninject container.

    = but =

    • Kephas makes extensive use of DI metadata, and from what I know Ninject does not support metadata.

    So you have the following options:

    • Use two DI containers. This may be practical for the time bridging the complete migration, but I would not recommend it for the long run.
    • Use another DI container supporting metadata. If you are not satisfied with the System.Composition (MEF) adapter, for which built-in support is provided, an alternative would be Autofac, but to use it you will have to provide the container adapter (which is not that complicated). By doing so you will have only one DI container.

    Conclusion: even if you don't have to change the DI framework, for the reasons provided above it is recommended to do it.

    You may want to check the DI wiki for more information.

    Disclaimer: I am the lead developer of Kephas Framework.