Are MEF exports cached or discovering every time on request?

前端 未结 3 1365
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 16:23

If I have one type MyClass, register with

[Export(typeof(Myclass))] attribute, and

[PartCreationPolicy(CreationPolicy.Shared)]

3条回答
  •  时光取名叫无心
    2021-01-05 16:50

    It does a lookup every time, when you use [PartCreationPolicy(CreationPolicy.NonShared)]. You then have to implement the caching yourself.

    The default implementation is using a Singleton pattern. This equals the attribute [PartCreationPolicy(CreationPolicy.Shared)]. This is the best practice.

    For more information, read http://blogs.microsoft.co.il/blogs/bnaya/archive/2010/01/09/mef-for-beginner-part-creation-policy-part-6.aspx

提交回复
热议问题