This project is read-only.

About Lazy Loading

Mono.Addins is designed to be fast, efficient in memory use and scalable. All information about add-ins and extensions is cached and lazy loaded.

To get a better idea of how information is loaded and cached, let's analyze the following example:

using System;
using Mono.Addins;

[assembly:AddinRoot ("HelloWorld", "1.0")]

class MainClass
{
	public static void Main (string[] args)
	{
		AddinManager.Initialize ();
		AddinManager.Registry.Update (null);
		
		foreach (TypeExtensionNode<CommandAttribute> node in AddinManager.GetExtensionNodes (typeof(ICommand))) {
			Console.WriteLine ("Running command {0}", node.Data.Label);
			ICommand cmd = node.CreateInstance ();
			cmd.Run ();
		}
	}
}

Let's see what is Mono.Addins is doing behind the scenes at every call:

AddinManager.Initialize ();

The Initialize call performs some initializations in the add-in engine. It does not load any add-in information.

AddinManager.Registry.Update ();

The Registry.Update call will scan the application directory looking for add-ins. Add-in information is stored in an ad-hoc database. This database has information about previous scans, so add-ins which have not changed will not be scanned again. The add-in scan is done in a separate domain, so it won't have any effect on the main application.

foreach (TypeExtensionNode<CommandAttribute> node in AddinManager.GetExtensionNodes (typeof(ICommand))) {

When doing the GetExtensionNodes call, Mono.Addins will get the list of extension nodes by querying the add-in registry. This operation doesn't involve any assembly loading. All information is retrieved from the add-in database, including extension metadata.

Console.WriteLine ("Running command {0}", node.Data.Label);

The previous GetExtensionNodes call returns nodes with all metadata, so this call here doesn't require any additional query to the add-in registry.

ICommand cmd = node.CreateInstance ();

The CreateInstance method needs to load a type from the add-in, so at this point it has to load the add-in assembly.

cmd.Run ();

The add-in assembly is loaded, so the command can be run.

Next topic: The Add-in Registry

Last edited May 20, 2010 at 8:02 PM by slluis, version 3

Comments

No comments yet.