GithubHelp home page GithubHelp logo

beppemarazzi / lazyassemblyloading Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lestera/lazyassemblyloading

0.0 2.0 0.0 23 KB

This library aims to extend MEF with a new catalog that supports lazy loading of plugin assemblies while still making their metadata available.

License: MIT License

C# 100.00%

lazyassemblyloading's Introduction

Synopsis

This library aims to extend MEF (Managed Extensibility Framework) with a new catalog that supports lazy loading of plugin assemblies while still making their metadata available. This is a proof of concept and was not tested in production so far.

Motivation

The motivation behind writing this library is to improve the performance of applications which rely heavily on MEF plugins. There are plenty of cases where an application loads all of its plugins, where in fact the user only actively uses a few of them. This results in wasteful memory usage and a performance hit to the application's startup, as all plugin assemblies have to be loaded. Using the LazyAssemblyCatalog class allows the application to:

  1. Start up quickly, as only necessary assemblies will be loaded on startup.
  2. Keep the memory footprint to a minimum. Plugin assemblies will only be loaded when they actually need to be used.
  3. Be able to access export metadata, even for plugins whose assemblies haven't been loaded yet.

Example usage

First we need to serialize the plugin assembly's part information. This should be done in advance - a good place to put this is probably the plugin's post-build event.

// Serialize assembly imports, exports, and metadata to file.
SerializationUtils.SerializeAssemblyPartInformation(typeof(MyPlugin).Assembly, @"C:\PartInformation.xml");

Now that we have the serialized part information, the application can create a LazyAssemblyCatalog from this data.

// Create the catalog and pass the serialized data
var catalog = new LazyAssemblyCatalog(@"C:\PartInformation.xml");

To avoid unnecessary assembly loading, imports should be wrapped in Lazy and use interfaces which are already loaded and available to the application, for example:

[ImportMany]
public Lazy<IPlugin, IPluginMetadata>[] Plugins { get; set; }

[Import]
public Lazy<IDependency> Dependency { get; set; }

A sample program can be found in the "Sample" folder.

Contribution

Feel free to make any contributions via pull requests.

lazyassemblyloading's People

Contributors

lestera avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.