C#使用MEF進行模塊化應用程序開發


MEF介紹

MEF全稱Managed Extensibility Framework ,是一個用於創建可擴展的輕量級應用程序的庫。 MEF 讓擴展不僅可在應用程序內重復使用,還可以跨程序重復使用。

MEF隨.Net Framework 4一起發布,默認命名空間是System.ComponentModel.Composition。稱為MEF1版本,在下面的文章中,MEF默認指MEF1版本

 

如果需要在.Net Core中使用MEF,可以使用Nuget包管理器安裝

1 Install-Package System.ComponentModel.Composition -Version 5.0.0-preview.6.20305.6

 

WPF/Winform中使用時,直接引用GAC中的System.ComponentModel.Composition即可

 

如果需要在Web應用程序中使用MEF

可以使用MEF2版本(支持.Net Core),默認命名空間是System.Composition

1 Install-Package System.Composition -Version 5.0.0-preview.6.20305.6

 

可通過以下鏈接,了解MEF1和MEF2的區別

https://github.com/dotnet/runtime/blob/master/src/libraries/System.ComponentModel.Composition/mef_guide/README.md

 

MEF2的使用方法可參見

C#高級編程(第10版) 第26章 Composition 754

 

附加內容:

Visual Studio的擴展功能使用了MEF框架來進行實現,可訪問以下鏈接了解更多信息

https://docs.microsoft.com/en-us/visualstudio/extensibility/managed-extensibility-framework-in-the-editor?view=vs-2019

 

MEF使用

MEF主要是通過導入、導出部件來實現應用程序的可擴展性。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM