How to use the Managed Extensions framework

Source: Internet
Author: User

There's been a lot of recent descriptions of the Managed Extensions framework, and while many people understand what it means, they don't understand how it works. Does this tool help customers add their own forms to the WPF program? We need these new forms in our menus, but we don't want the VB source code to be recompiled by the client. This article will teach you how to use the Managed Extensions framework.

That sounds like an effective application to MEF. You can also use the same method to apply to WinForms or asp.net, and C # code is similar to the code shown below.

MEF is an extended model that enables components to interact with a simple model. The MEF invokes part of the component. MEF is extensible for different schema types, but it also comes with a property model. So you can get through. NET property defines the interaction of a part. If a part needs something, it uses the Import property, and if it supplies something, it uses the export attribute. Any part can be used as a host or client, vendor, or customer. These interactions of MEF are based on protocol and provide a flexible excavation model. Your application sends a request to the MEF to provide execution. This allows the application to detach and allow you to perform the substitution.

MEF is currently only available as a preview version on CodePlex. It is in the System.ComponentModel namespace, indicating that it will appear as a full-fledged member of the. NET Framework 4.0. Some Microsoft projects will be related, including the VS 2010 Code Editor. In it has not yet appeared in. NET Framework, we all need to download the MEF and put System.ComponentModel.Composition.dll in an accessible article. You also need to be aware that the application interface may change.

The application will be the host of the MEF and the customer will write out the MEF client or extension. Extensions are easy to write to clients because hosts must manage Compositioncontainer. We'll explain the process by creating an interface, creating extensions, and creating a WPF host. The WPF master sends a directory to Compositioncontainer, which specifies the directory to use for the Search menu extension.

Extended support for the agreements entered into. The most common protocols are interfaces, and these interfaces are simple.

Public Interface IExtension
   Sub ShowWindow()
   End Interface
   客户可以通过执行这一接口来添加扩展并从System.ComponentModel.Composition命名空间中指定Export属性:
   Export(GetType(IExtension))> _
    _
   Partial Public Class First
   Implements IExtension
   Public Sub ShowWindow() _
   Implements Common.IExtension.ShowWindow
   End Sub
   End Class

You can also use any string to determine the output, but the most common extension is to retrieve it through an interface protocol. The ExportMetaData property contains additional extended information that the host can retrieve without actually showing the underlying object, allowing us to control the sample and protect performance.

When you design a scenario, you set the interface to be referenced separately by the host and all extension components. Do not establish a direct reference between the host and the extension. All components need to refer to System.ComponentModel.Composition.dll. The compiled extensions should be placed in a convenient location. You can specify the location you want to create in the Properties dialog box.

The host wants to manage Compositioncontainer. Compositioncontainer is connected to the input and output behind the scenes, and it must understand the output that can be obtained. Create a container project-level variable to clean up the onexit. The container Dispose method call handles all parts that perform IDisposable:

Protected Overrides Sub OnExit( _
   ByVal e As System.Windows.ExitEventArgs)
   MyBase.OnExit(e)
   If mContainer IsNot Nothing Then
   mContainer.Dispose()
   End If
   End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.