当前位置:网站首页>MEF framework learning record
MEF framework learning record
2022-06-26 05:51:00 【self85】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
List of articles
Preface
Managed Extensibility Framework (MEF) Is a library for creating extensible lightweight applications . It allows application developers to To discover and use extensions without configuration . It also allows extension developers to easily encapsulate code and avoid fragile tight dependencies . MEF Let expand Exhibition can not only be reused in the application , It can also be reused across programs .One 、 Scalability issues
Imagine you are the designer of a large application that must support extensibility . Your application must contain as many smaller components as possible , And it is responsible for creating and running smaller components . The easiest way to solve the problem is to include components as source code in your application and call them directly from the code . There are many obvious disadvantages . most important of all , You cannot add a new component without debugging the source code , This is an acceptable limitation ( For example, in Web Applications
Preface ), But not for client applications . The same problem is , You cannot access the source code of the component , Because components may have been developed by third parties , At the same time, for the same reason, you cannot allow third parties to access your source code . A slightly more sophisticated approach is to provide extension points or interfaces to allow separation between applications and components . Under this module , You may provide interfaces that components can implement and that enable interfaces to interact with applications API. This solves the problem of requiring source code access , But it still has its own problems . Because the application lacks the ability to discover components by itself , Therefore, it must be clearly indicated which components are available and should be loaded . This is usually done in the configuration file
The available components are clearly documented in . This means ensuring that the component correctly becomes a maintenance issue , This is especially true when the person requesting the update is the end user, not the developer .
Besides , Components can communicate with other components , In addition to strictly defined channels through the application itself . There is usually no case where the application designer does not anticipate the needs of a particular communication .
Final , Component developers must accept the hard dependencies of the assembly containing the interfaces they implement . This makes it possible to
Using components becomes difficult , And it can cause problems when you create a component's test framework .
Two 、 Import and export Basics
export Is a value that the component provides to other components in the container , and Import It is the requirement of the part for the container to be filled by the available Export . In the characterized programming model , Import and export are used by Import and Export A decorated class or member declaration of a property . Export Attributes can modify classes 、 Field 、 Properties or methods , and Import Properties can decorate fields 、 Property or constructor parameter . To match the import with the export , The import and the export must have the same agreement . The contract consists of a string ( be called Agreement name ) And types of exported or imported objects ( be called Type of agreement ) form . Only if the contract name and contract type match , It is considered that the export can meet the specific requirements
Enter into . Either or both of the protocol parameters may be implicit or explicit . The following code example demonstrates a class that declares a base import .
public class MyClass
{
[Import]
public IMyAddin MyAddin {
get; set; }
}
In this import , Import Attribute has neither contract type parameter attached , The contract name parameter is not attached . therefore , Both will be inferred from the attributes of the modifier . under these circumstances , Contract type will be IMyAddin , The contract name will be a unique string created based on the contract type . ( In other words , The contract name will only be of the same type as its name IMyAddin Inferred export matches .)
[Export(typeof(IMyAddin))]
public class MyLogger : IMyAddin {
}
In this export , Because the contract type is specified as IMyAddin The parameters of the property , Therefore, the contract type is Export . The exported type must be the same as the contract type 、 Derived from contract type , Or implement the contract type ( If the exported type is interface ). In this export , Actual type MyLogger Implementation interface IMyAddin . The contract name is inferred from the contract type , This means that this export will match the previous import .
summary
You should usually declare exports and imports for public classes or members . Other statements are also supported , But if you export or import private members 、 Protected or internal members , The isolated model of the component will be damaged , Therefore, it is recommended not to do so .
边栏推荐
- MySQL database-01 database overview
- Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast
- Machine learning 07: Interpretation of PCA and its sklearn source code
- [C language] deep analysis of data storage in memory
- 小程序如何关联微信小程序二维码,实现二码聚合
- 解决在win10下cmder无法使用find命令
- How Navicat reuses the current connection information to another computer
- Project suspension
- 怎么把平板作为电脑的第二扩展屏幕
- Thinking about bad money expelling good money
猜你喜欢

Prototype mode, Baa Baa

How Navicat reuses the current connection information to another computer

Kolla ansible deploy openstack Yoga version

原型模式,咩咩乱叫

通俗易懂的从IDE说起,再谈谈小程序IDE

Sofa weekly | open source person - Yu Yu, QA this week, contributor this week

解决在win10下cmder无法使用find命令
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast

Navicat如何将当前连接信息复用另一台电脑

Consul service registration and discovery
随机推荐
卷妹带你学jdbc---2天冲刺Day2
家庭记账程序(第一版)
Day4 branch and loop
MySQL数据库-01数据库概述
Pre-Sale Analysis
类和对象的学习
How to associate wechat applet QR code to realize two code aggregation
Machine learning 07: Interpretation of PCA and its sklearn source code
Life is so fragile
Bubble sort
AutowiredAnnotationBeanPostProcessor什么时候被实例化的?
Uni app ceiling fixed style
怎么把平板作为电脑的第二扩展屏幕
花生壳内网穿透映射NPM私服问题
Sofa weekly | open source person - Yu Yu, QA this week, contributor this week
【 langage c】 stockage des données d'analyse approfondie en mémoire
售前分析
cross entropy loss = log softmax + nll loss
Easy to understand from the IDE, and then talk about the applet IDE
Consul服务注册与发现