What is it?
MAF is the plugin/addin framework for .NET applications. It allows application developers to expose very simple extensibility points that allows third party developers to enhance your product. Common examples are creating an email client and relying on AddIns for services like Spell Checking, Virus Scanning, etc. Whether plugins are a core part of your application or merely a small feature, the Managed AddIn Framework should be employed to your advantage from here on out.
Note: System.AddIn is a .NET 3.5 assembly, and as such means that you must target .NETFX 3.5 to utilize it.
MAF consists of the following assemblies
1. System.AddIn
2. System.AddIn.Contract
MAF gives your application the following benefits (at the expense of extra complexity and a steeper learning curve)
Discovery – Find addins at runtime
Activation – Load an addin at runtime
Versioning - Backwards/forward compatibility
Isolation – Load addins into separate AppDomains/Processes so they cannot crash they whole app, among other reasons
Lifetime Management – MAF will handle addin lifetimes and memory/AppDomain management
Sandboxing – Load addins with specific permission sets like “Internet”
Unloading – Unload an addin without worrying about tedious AppDomain management
Discovery – Find addins at runtime
Activation – Load an addin at runtime
Versioning - Backwards/forward compatibility
Isolation – Load addins into separate AppDomains/Processes so they cannot crash they whole app, among other reasons
Lifetime Management – MAF will handle addin lifetimes and memory/AppDomain management
Sandboxing – Load addins with specific permission sets like “Internet”
Unloading – Unload an addin without worrying about tedious AppDomain management
Once you build your addin folder, you can use the following code to discover the addin token. I am not giving exact
synatx, just code logic only....
synatx, just code logic only....
AddInStore.Update(path);; We’re telling the AddInStore to update itself and look for AddIns withthe given root path.
Collection addinTokens = AddInStore.FindAddIns( typeof(XXXXX), PipelineStoreLocation.ApplicationBase); which basically asks the AddInStore to find the AddIns available of a given type.1. The application domain is created with the permissions specifi ed.
2. The assembly of the add - in is loaded into the new application domain with the Assembly.LoadFrom()
method.
3. The default constructor of the add - in is invoked by using refl ection. Because the add - in derives from the
base class that is defi ned with the add - in view, the assembly of the view is loaded as well.
4. An instance of the add - in side adapter is constructed. The instance of the add - in is passed to the
constructor of the adapter, so the adapter can connect the contract to the add - in. The add - in adapter
derives from the base class MarshalByRefObject, so it can be invoked across application domains.
5. The activation code returns a proxy to the add - in side adapter to the application domain of the hosting
application. Because the add - in adapter implements the contract interface, the proxy contains methods
and properties of the contract interface.
6. An instance of the host side adapter is constructed in the application domain of the hosting application.
The proxy of the add - in side adapter is passed to the constructor. The activation fi nds the type of
host - side adapter from the add - in token. The host- view( base calss of host-side adapter) is returned to the hosting application.
No comments:
Post a Comment