当前位置:网站首页>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 .
边栏推荐
- bingc(继承)
- [activity recommendation] cloud native, industrial Internet, low code, Web3, metauniverse... Which is the architecture hot spot in 2022
- About XXX management system (version C)
- Household accounting procedures (First Edition)
- 421- binary tree (226. reversed binary tree, 101. symmetric binary tree, 104. maximum depth of binary tree, 222. number of nodes of complete binary tree)
- Use jedis to monitor redis stream to realize message queue function
- one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
- Adapter mode
- Leetcode513. Find the value in the lower left corner of the tree
- Pytorch (network model)
猜你喜欢

Pytorch (network model)

uniCloud云开发获取小程序用户openid

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

Kolla ansible deploy openstack Yoga version

Bubble sort

REUSE_ALV_GRID_DISPLAY 事件实现(DATA_CHANGED)

状态模式,身随心变

The difference between get and post in small interview questions

【C語言】深度剖析數據在內存中的存儲

421- binary tree (226. reversed binary tree, 101. symmetric binary tree, 104. maximum depth of binary tree, 222. number of nodes of complete binary tree)
随机推荐
操作符的优先级、结合性、是否控制求值顺序【详解】
Pytorch (network model training)
Ribbon负载均衡服务调用
[activity recommendation] cloud native, industrial Internet, low code, Web3, metauniverse... Which is the architecture hot spot in 2022
Status mode, body can change at will
When was the autowiredannotationbeanpostprocessor instantiated?
[PHP] PHP two-dimensional array is sorted by multiple fields
BOM document
Posting - don't get lost in the ocean of Technology
状态模式,身随心变
Machine learning 07: Interpretation of PCA and its sklearn source code
力扣 875. 爱吃香蕉的珂珂
怎么把平板作为电脑的第二扩展屏幕
MySQL source code reading (II) login connection debugging
Daily production training report (17)
卷妹带你学jdbc---2天冲刺Day2
421- binary tree (226. reversed binary tree, 101. symmetric binary tree, 104. maximum depth of binary tree, 222. number of nodes of complete binary tree)
DOM document
Bubble sort
Win socket programming (Mengxin initial battle)