Is there a replacement for MEF in .NET Core (or ASP.NET 5)
Asked Answered
Z

1

18

We know that .NET Core (the open-source components) are only a subset of the full .NET Framework, and that ASP.NET 5 (and MVC 6) is built on .NET Core. Does this mean that Managed Extensibility Framework (MEF) is not available in ASP.NET 5?

If so, is there any replacement for dynamic extensibility available in .NET Core?

I have a number of applications that use MEF to dynamically load plugins and external integrations and it would be a pity if they were locked into the .NET Framework just because they use MEF.

Zest answered 2/3, 2015 at 1:9 Comment(3)
MEF is definitely supported in the .Net 4.6 Preview.Touraine
you can also probably use nuget.org/packages/microsoft.compositionTouraine
@Touraine I noticed that, but 4.6 is only the full framework, no Core. MEF isn't appearing in the corefx repo, so I'm not sure it's included. Also, that NuGet package lists as only supported on .NET Framework, but if it works in a PCL, I might be able to reference that from a vNext/5 project..Zest
F
9

The existing NuGet package should work. It's portable, and .NET Core is a backward-compatible evolution of the portable API surface. ASP.NET Core won't automatically install it, however because the package doesn't explicitly say that it's compatible with .NET Core.

To install the package, you'll need to add an imports section to your project.json:

{
  "dependencies": {
    "Microsoft.Composition": "1.0.30"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": "portable-net45+win8"
    }
  }
}
Fecal answered 2/3, 2015 at 17:3 Comment(3)
Which existing package? There appear to be several by now.Phyliciaphylis
Microsoft.Composition, but you may need to add "imports": "portable-net45+win8" to your project.json nowadays.Fecal
Answer revised for the current state of things.Fecal

© 2022 - 2024 — McMap. All rights reserved.