Is MEF OSGi for .NET?

橙三吉。 提交于 2019-11-30 06:42:59

问题


I'm just trying to get my head around the Managed Extensibility Framework (MEF) at the moment and digging into a bit. I have an Eclipse background so in my brain I currently have the equation:

MEF =~ OSGi for .NET

Based on what I have heard so far. Am I on the right lines?


回答1:


Scott Hanselman helped to highlights the specifics about MEF in his podcast 148 with Glenn Block.

Compared to OSGi, MEF is built upon "Inversion of Control" and OSGi is not: it (OSGi) will discover new bundle through a different mechanism based on a Life Cycle Layer.

MEF is focused on application extensibility. It uses DI as a strategy for composing the different extensions, however it is not in itself a generic DI container.

Since the last point can be confusing, the transcripts of the podcast can help:

The way I basically position it though, the difference between the two, is that IoC containers are really about managing a known set of things in different environments, like I want a logger in my disk environment, I want a mock logger in my test environment.

So MEF is really about managing an unknown set of things and what that boils down to is that in an IoC Container I tend to do either a convention-based or a registration, specific registration mechanism, to say here's what logger means, here's what this means, here's what that means.

MEF uses the code and a discovery mechanism and annotations on the code, which are attributes, where whatever shows up in the system, that's what's there.

So again, taking it to a higher level, it's about you use MEF to really manage a set of unknown things, you use IoC Containers to manage a set of known things.

Conclusion: (one of) the main difference is the discovery principle (IoC vs. lifecycle)




回答2:


Notice that OSGi is designed so that an IoC container can be provided on top of it as a module, actually, there are multiple IoC containers for OSGi available as well as other mechanisms: DS, iPOJO, Blueprint, and undoubtedly others.




回答3:


Just stumbled upon this, but Prism seems to be the closest thing to OSGi in .NET I've seen! Look at their Modular Application Development section in the docs.

Just look at their example of the module dependencies (almost equivalent to bundles!):

<modules>
  <module assemblyFile="Modules/ModuleD.dll" moduleType="ModuleD.ModuleD, ModuleD" moduleName="ModuleD">
    <dependencies>
      <dependency moduleName="ModuleB"/>
    </dependencies>
</module>

It seems like over at Microsoft, the Patterns & Practices team serves as a kind-of OSGi Alliance equivalent.



来源:https://stackoverflow.com/questions/709532/is-mef-osgi-for-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!