当前位置:网站首页>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 .
边栏推荐
- Pytorch (network model)
- Talk 5 wireless communication
- 状态模式,身随心变
- Leetcode513. Find the value in the lower left corner of the tree
- [activity recommendation] cloud native, industrial Internet, low code, Web3, metauniverse... Which is the architecture hot spot in 2022
- About XXX management system (version C)
- Given two corresponding point sets AB, how to estimate the parameters of the specified transformation matrix R?
- 花生壳内网穿透映射NPM私服问题
- June 3 is a happy day
- The difference between get and post in small interview questions
猜你喜欢

423- binary tree (110. balanced binary tree, 257. all paths of binary tree, 100. same tree, 404. sum of left leaves)

How to use the tablet as the second extended screen of the PC
![[arm] build boa based embedded web server on nuc977](/img/fb/7dc1898e35ed78b417770216b05286.png)
[arm] build boa based embedded web server on nuc977

Combined mode, transparent mode and secure mode

Using Jenkins to perform testng+selenium+jsup automated tests and generate extendreport test reports

DOM文档

家庭记账程序(第一版)

There are applications related to web network request API in MATLAB (under update)

Status mode, body can change at will

REUSE_ALV_GRID_DISPLAY 事件实现(DATA_CHANGED)
随机推荐
Implementation of third-party wechat authorized login for applet
Pre-Sale Analysis
Data storage: the difference between MySQL InnoDB and MyISAM
How Navicat reuses the current connection information to another computer
Pytorch (network model)
虚拟项目失败感想
生命原来如此脆弱
【C语言】深度剖析数据在内存中的存储
写在父亲节前
Learn cache lines and pseudo sharing of JVM slowly
劣币驱逐良币的思考
Operator priority, associativity, and whether to control the evaluation order [detailed explanation]
The most refined language interprets the event dispatcher (also known as the event scheduler)
[MySQL] MySQL million level data paging query method and its optimization
Feelings of virtual project failure
Summary of the 10th provincial Blue Bridge Cup
电商借助小程序技术发力寻找增长突破口
Gram 矩阵
使用Jenkins执行TestNg+Selenium+Jsoup自动化测试和生成ExtentReport测试报告
Project suspension