.NET MEF: part versioning

146 views Asked by At

I'm exploring MEF, introduced in .NET 4.0, and I haven't found on the official documentation or on any other websites a real way to manage versioning.

I found this question MEF Dependencies and versioning but the answers are not satisfactory: it seems to me that with strong naming the core and the plugin are too coupled.

My example:

  • part A import an interface ICar (version 1.0)
  • part B export an interface ICar

Everything works happily. After the release I decide to modify ICar to have a version 1.1 with a more complex ICar interface. Clearly part B cannot be loaded anymore. How is the best practice here? Obviously the correct way is not to change the interface ICar. But is changing ICar the neatest way? On a blog I found that you need to:

  • create ICar2 instead of changing ICar
  • create (manually) an adapter for ICar
  • import both ICar2 and ICar and the latter needs to be adapted to ICar2 using the adapter.

It seems that System.Addin (MAF) manages this scenario with a built in solution.

Any ideas so far?

BTW, MEF seems a real good technology, but the official documentation is not enough (as usual for Microsoft...)

1

There are 1 answers

2
Stephen Dunne On

You could use Interface segregation here to try to simplify this. In your example you have ICart, so for the new functionality you could create a new interface ICarExtra with the new properties/methods (if you want this could implement the original ICar interface)

So now your PartB can still satisfy any import of ICart but you can have a newer PartC with the additional functionality that can satisfy an import of ICartExtra.

Alternatively, for a far more complex solution, you could create your own version of CompositionContainer and override the ComposeParts method with some custom functionality to make a more informed decision.