开发者

When to use MEF [closed]

开发者 https://www.devze.com 2022-12-30 22:04 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit 开发者_如何转开发the help center for guidance. Closed 10 years ago.

I tried Unity and MEF and plain old new. And I am a bit confused as to when exactly you need to use any of these "patterns". Why would I choose to use MEF or Unity if using new is simpler and satisfies my needs.

In other words, what needs justify the use of MEF or Unity?


MEF allows for isolation of subsystems within an application. This isolation is useful if you need to change subsystem implementations often, or even at runtime. MEF takes care of the details of loading the subsystems and wiring up all the providers to the appropriate consumers. It's a giant step forward toward the ideal of building an application by concatenating a set of self-contained modules that know nothing about each other.

A significant portion of the code in a traditional application is dedicated to simply gluing things together - glue code. MEF drastically reduces the need for glue code.

If you're just constructing an object so you can open a file or show a dialog, that's not what MEF is for. If you're wanting to write code that uses a generic xyz service but don't want to hard-code a dependency on vendor a or vendor b implementations, that might be a MEF candidate.

0

精彩评论

暂无评论...
验证码 换一张
取 消