Index: /trunk/sources/HeuristicLab.PluginInfrastructure/ApplicationManager.cs
===================================================================
--- /trunk/sources/HeuristicLab.PluginInfrastructure/ApplicationManager.cs	(revision 3246)
+++ /trunk/sources/HeuristicLab.PluginInfrastructure/ApplicationManager.cs	(revision 3247)
@@ -35,8 +35,8 @@
   /// <summary>
   /// The ApplicationManager has a reference to the application manager singleton.
-  /// The application manager provides
   /// </summary>
-  public sealed class ApplicationManager : MarshalByRefObject, IApplicationManager {
-    private static IApplicationManager appManager;
+  public static class ApplicationManager {
+    // the singleton instance is initialized to LightweightApplicationManager as long as no other application manager is registered
+    private static IApplicationManager appManager = new LightweightApplicationManager();
     /// <summary>
     /// Gets the application manager singleton.
@@ -47,273 +47,13 @@
 
     /// <summary>
-    /// Fired when a plugin is loaded.
-    /// </summary>
-    internal event EventHandler<PluginInfrastructureEventArgs> PluginLoaded;
-    /// <summary>
-    /// Fired when a plugin is unloaded (when the application terminates).
-    /// </summary>
-    internal event EventHandler<PluginInfrastructureEventArgs> PluginUnloaded;
-
-    // cache for the AssemblyResolveEvent 
-    // which must be handled when assemblies are loaded dynamically after the application start
-    private Dictionary<string, Assembly> loadedAssemblies;
-
-    private List<IPlugin> loadedPlugins;
-
-    private List<PluginDescription> plugins;
-    /// <summary>
-    /// Gets all plugins.
-    /// </summary>
-    public IEnumerable<IPluginDescription> Plugins {
-      get { return plugins.Cast<IPluginDescription>(); }
-    }
-
-    private List<ApplicationDescription> applications;
-    /// <summary>
-    /// Gets all installed applications.
-    /// </summary>
-    public IEnumerable<IApplicationDescription> Applications {
-      get { return applications.Cast<IApplicationDescription>(); }
-    }
-
-    internal ApplicationManager()
-      : base() {
-      loadedAssemblies = new Dictionary<string, Assembly>();
-      loadedPlugins = new List<IPlugin>();
-      AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
-        if (loadedAssemblies.ContainsKey(args.Name)) {
-          return loadedAssemblies[args.Name];
-        }
-        return null;
-      };
-    }
-
-    /// <summary>
-    /// Prepares the application domain for the execution of an HL application.
-    /// Pre-loads all <paramref name="plugins"/>.
-    /// </summary>
-    /// <param name="apps">Enumerable of available HL applications.</param>
-    /// <param name="plugins">Enumerable of plugins that should be pre-loaded.</param>
-    internal void PrepareApplicationDomain(IEnumerable<ApplicationDescription> apps, IEnumerable<PluginDescription> plugins) {
-      this.plugins = new List<PluginDescription>(plugins);
-      this.applications = new List<ApplicationDescription>(apps);
-      RegisterApplicationManager((IApplicationManager)this);
-      LoadPlugins(plugins);
-    }
-
-    /// <summary>
     /// Registers a new application manager.
     /// </summary>
     /// <param name="manager"></param>
     internal static void RegisterApplicationManager(IApplicationManager manager) {
-      if (appManager != null) throw new InvalidOperationException("The application manager has already been set.");
-      appManager = manager;
-    }
-
-    /// <summary>
-    /// Loads the <paramref name="plugins"/> into this application domain.
-    /// </summary>
-    /// <param name="plugins">Enumerable of plugins that should be loaded.</param>
-    private void LoadPlugins(IEnumerable<PluginDescription> plugins) {
-      // load all loadable plugins (all dependencies available) into the execution context
-      foreach (var desc in PluginDescriptionIterator.IterateDependenciesBottomUp(plugins.Where(x => x.PluginState != PluginState.Disabled))) {
-        foreach (string fileName in desc.AssemblyLocations) {
-          var asm = Assembly.LoadFrom(fileName);
-          RegisterLoadedAssembly(asm);
-          // instantiate and load all plugins in this assembly
-          foreach (var plugin in GetInstances<IPlugin>(asm)) {
-            plugin.OnLoad();
-            loadedPlugins.Add(plugin);
-          }
-        }
-        OnPluginLoaded(new PluginInfrastructureEventArgs(desc));
-        desc.Load();
+      if (!(appManager is LightweightApplicationManager)) throw new InvalidOperationException("The application manager has already been set.");
+      else {
+        appManager = manager;
       }
     }
-
-    /// <summary>
-    /// Runs the application declared in <paramref name="appInfo"/>.
-    /// This is a synchronous call. When the application is terminated all plugins are unloaded.
-    /// </summary>
-    /// <param name="appInfo">Description of the application to run</param>
-    internal void Run(ApplicationDescription appInfo) {
-      IApplication runnablePlugin = (IApplication)Activator.CreateInstance(appInfo.DeclaringAssemblyName, appInfo.DeclaringTypeName).Unwrap();
-      try {
-        runnablePlugin.Run();
-      }
-      finally {
-        // unload plugins in reverse order
-        foreach (var plugin in loadedPlugins.Reverse<IPlugin>()) {
-          plugin.OnUnload();
-        }
-        foreach (var desc in PluginDescriptionIterator.IterateDependenciesBottomUp(plugins.Where(x => x.PluginState != PluginState.Disabled))) {
-          desc.Unload();
-          OnPluginUnloaded(new PluginInfrastructureEventArgs(desc));
-        }
-      }
-    }
-
-    /// <summary>
-    /// Loads raw assemblies dynamically from a byte array
-    /// </summary>
-    /// <param name="assemblies">bytearray of all raw assemblies that should be loaded</param>
-    internal void LoadAssemblies(IEnumerable<byte[]> assemblies) {
-      foreach (byte[] asm in assemblies) {
-        Assembly loadedAsm = Assembly.Load(asm);
-        RegisterLoadedAssembly(loadedAsm);
-      }
-    }
-
-    // register assembly in the assembly cache for the AssemblyResolveEvent
-    private void RegisterLoadedAssembly(Assembly asm) {
-      loadedAssemblies.Add(asm.FullName, asm);
-      loadedAssemblies.Add(asm.GetName().Name, asm); // add short name
-    }
-
-    /// <summary>
-    /// Creates an instance of all types that are subtypes or the same type of the specified type and declared in <paramref name="plugin"/>
-    /// </summary>
-    /// <typeparam name="T">Most general type.</typeparam>
-    /// <returns>Enumerable of the created instances.</returns>
-    internal static IEnumerable<T> GetInstances<T>(IPluginDescription plugin) where T : class {
-      return from t in GetTypes(typeof(T), plugin, true)
-             select (T)Activator.CreateInstance(t);
-    }
-    /// <summary>
-    /// Creates an instance of all types declared in assembly <paramref name="asm"/> that are subtypes or the same type of the specified <typeparamref name="type"/>. 
-    /// </summary>
-    /// <typeparam name="T">Most general type.</typeparam>
-    /// <param name="asm">Declaring assembly.</param>
-    /// <returns>Enumerable of the created instances.</returns>
-    private static IEnumerable<T> GetInstances<T>(Assembly asm) where T : class {
-      return from t in GetTypes(typeof(T), asm, true)
-             select (T)Activator.CreateInstance(t);
-    }
-    /// <summary>
-    /// Creates an instance of all types that are subtypes or the same type of the specified type
-    /// </summary>
-    /// <typeparam name="T">Most general type.</typeparam>
-    /// <returns>Enumerable of the created instances.</returns>
-    internal static IEnumerable<T> GetInstances<T>() where T : class {
-      return from i in GetInstances(typeof(T))
-             select (T)i;
-    }
-
-    /// <summary>
-    /// Creates an instance of all types that are subtypes or the same type of the specified type
-    /// </summary>
-    /// <param name="type">Most general type.</param>
-    /// <returns>Enumerable of the created instances.</returns>
-    internal static IEnumerable<object> GetInstances(Type type) {
-      return (from t in GetTypes(type, true)
-              select Activator.CreateInstance(t)).ToList();
-    }
-
-    /// <summary>
-    /// Finds all types that are subtypes or equal to the specified type.
-    /// </summary>
-    /// <param name="type">Most general type for which to find matching types.</param>
-    /// <param name="onlyInstantiable">Return only types that are instantiable 
-    /// (interfaces, abstract classes... are not returned)</param>
-    /// <returns>Enumerable of the discovered types.</returns>
-    internal static IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable) {
-      return from asm in AppDomain.CurrentDomain.GetAssemblies()
-             from t in GetTypes(type, asm, onlyInstantiable)
-             select t;
-    }
-
-    /// <summary>
-    /// Finds all types that are subtypes or equal to the specified type if they are part of the given
-    /// <paramref name="pluginDescription"/>.
-    /// </summary>
-    /// <param name="type">Most general type for which to find matching types.</param>
-    /// <param name="pluginDescription">The plugin the subtypes must be part of.</param>
-    /// <param name="onlyInstantiable">Return only types that are instantiable 
-    /// (interfaces, abstract classes... are not returned)</param>
-    /// <returns>Enumerable of the discovered types.</returns>
-    internal static IEnumerable<Type> GetTypes(Type type, IPluginDescription pluginDescription, bool onlyInstantiable) {
-      PluginDescription pluginDesc = (PluginDescription)pluginDescription;
-      return from asm in AppDomain.CurrentDomain.GetAssemblies()
-             where !IsDynamicAssembly(asm)
-             where pluginDesc.AssemblyLocations.Any(location => location.Equals(Path.GetFullPath(asm.Location), StringComparison.CurrentCultureIgnoreCase))
-             from t in GetTypes(type, asm, onlyInstantiable)
-             select t;
-    }
-
-    private static bool IsDynamicAssembly(Assembly asm) {
-      return (asm is System.Reflection.Emit.AssemblyBuilder) || string.IsNullOrEmpty(asm.Location);
-    }
-
-    /// <summary>
-    /// Gets types that are assignable (same of subtype) to the specified type only from the given assembly.
-    /// </summary>
-    /// <param name="type">Most general type we want to find.</param>
-    /// <param name="assembly">Assembly that should be searched for types.</param>
-    /// <param name="onlyInstantiable">Return only types that are instantiable 
-    /// (interfaces, abstract classes...  are not returned)</param>
-    /// <returns>Enumerable of the discovered types.</returns>
-    private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable) {
-      return from t in assembly.GetTypes()
-             where type.IsAssignableFrom(t)
-             where onlyInstantiable == false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType)
-             select t;
-    }
-
-    private void OnPluginLoaded(PluginInfrastructureEventArgs e) {
-      if (PluginLoaded != null) PluginLoaded(this, e);
-    }
-
-    private void OnPluginUnloaded(PluginInfrastructureEventArgs e) {
-      if (PluginUnloaded != null) PluginUnloaded(this, e);
-    }
-
-    // infinite lease time
-    /// <summary>
-    /// Initializes the life time service with infinite lease time.
-    /// </summary>
-    /// <returns><c>null</c>.</returns>
-    public override object InitializeLifetimeService() {
-      return null;
-    }
-
-    #region IApplicationManager Members
-
-    IEnumerable<T> IApplicationManager.GetInstances<T>() {
-      return GetInstances<T>();
-    }
-
-    IEnumerable<object> IApplicationManager.GetInstances(Type type) {
-      return GetInstances(type);
-    }
-
-    IEnumerable<Type> IApplicationManager.GetTypes(Type type) {
-      return GetTypes(type, true);
-    }
-
-    IEnumerable<Type> IApplicationManager.GetTypes(Type type, bool onlyInstantiable) {
-      return GetTypes(type, onlyInstantiable);
-    }
-
-    IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin) {
-      return GetTypes(type, plugin, true);
-    }
-
-    IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable) {
-      return GetTypes(type, plugin, onlyInstantiable);
-    }
-
-
-    /// <summary>
-    /// Finds the plugin that declares the <paramref name="type">type</paramref>.
-    /// </summary>
-    /// <param name="type">The type of interest.</param>
-    /// <returns>The description of the plugin that declares the given type or null if the type has not been declared by a known plugin.</returns>
-    public IPluginDescription GetDeclaringPlugin(Type type) {
-      foreach (PluginDescription info in Plugins) {
-        if (info.AssemblyLocations.Contains(Path.GetFullPath(type.Assembly.Location))) return info;
-      }
-      return null;
-    }
-    #endregion
   }
 }
Index: /trunk/sources/HeuristicLab.PluginInfrastructure/DefaultApplicationManager.cs
===================================================================
--- /trunk/sources/HeuristicLab.PluginInfrastructure/DefaultApplicationManager.cs	(revision 3247)
+++ /trunk/sources/HeuristicLab.PluginInfrastructure/DefaultApplicationManager.cs	(revision 3247)
@@ -0,0 +1,304 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Security.Policy;
+using System.Reflection;
+using System.Diagnostics;
+using System.Security.Permissions;
+using System.Security;
+using System.Linq;
+using HeuristicLab.PluginInfrastructure.Manager;
+using System.IO;
+
+namespace HeuristicLab.PluginInfrastructure {
+
+  /// <summary>
+  /// The DefaultApplicationManager provides properties to retrieve the list of available plugins and applications.
+  /// It also provides methods for type discovery and instantiation for types declared in plugins.
+  /// The DefaultApplicationManager is registered as ApplicationManager.Manager singleton for each HL application
+  /// started via the plugin infrastructure.
+  /// </summary>
+  internal sealed class DefaultApplicationManager : MarshalByRefObject, IApplicationManager {
+    /// <summary>
+    /// Fired when a plugin is loaded.
+    /// </summary>
+    internal event EventHandler<PluginInfrastructureEventArgs> PluginLoaded;
+    /// <summary>
+    /// Fired when a plugin is unloaded (when the application terminates).
+    /// </summary>
+    internal event EventHandler<PluginInfrastructureEventArgs> PluginUnloaded;
+
+    // cache for the AssemblyResolveEvent 
+    // which must be handled when assemblies are loaded dynamically after the application start
+    private Dictionary<string, Assembly> loadedAssemblies;
+
+    private List<IPlugin> loadedPlugins;
+
+    private List<PluginDescription> plugins;
+    /// <summary>
+    /// Gets all plugins.
+    /// </summary>
+    public IEnumerable<IPluginDescription> Plugins {
+      get { return plugins.Cast<IPluginDescription>(); }
+    }
+
+    private List<ApplicationDescription> applications;
+    /// <summary>
+    /// Gets all installed applications.
+    /// </summary>
+    public IEnumerable<IApplicationDescription> Applications {
+      get { return applications.Cast<IApplicationDescription>(); }
+    }
+
+    internal DefaultApplicationManager()
+      : base() {
+      loadedAssemblies = new Dictionary<string, Assembly>();
+      loadedPlugins = new List<IPlugin>();
+      AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
+        if (loadedAssemblies.ContainsKey(args.Name)) {
+          return loadedAssemblies[args.Name];
+        }
+        return null;
+      };
+    }
+
+    /// <summary>
+    /// Prepares the application domain for the execution of an HL application.
+    /// Pre-loads all <paramref name="plugins"/>.
+    /// </summary>
+    /// <param name="apps">Enumerable of available HL applications.</param>
+    /// <param name="plugins">Enumerable of plugins that should be pre-loaded.</param>
+    internal void PrepareApplicationDomain(IEnumerable<ApplicationDescription> apps, IEnumerable<PluginDescription> plugins) {
+      this.plugins = new List<PluginDescription>(plugins);
+      this.applications = new List<ApplicationDescription>(apps);
+      ApplicationManager.RegisterApplicationManager(this);
+      LoadPlugins(plugins);
+    }
+
+    /// <summary>
+    /// Loads the <paramref name="plugins"/> into this application domain.
+    /// </summary>
+    /// <param name="plugins">Enumerable of plugins that should be loaded.</param>
+    private void LoadPlugins(IEnumerable<PluginDescription> plugins) {
+      // load all loadable plugins (all dependencies available) into the execution context
+      foreach (var desc in PluginDescriptionIterator.IterateDependenciesBottomUp(plugins.Where(x => x.PluginState != PluginState.Disabled))) {
+        foreach (string fileName in desc.AssemblyLocations) {
+          var asm = Assembly.LoadFrom(fileName);
+          RegisterLoadedAssembly(asm);
+          // instantiate and load all plugins in this assembly
+          foreach (var plugin in GetInstances<IPlugin>(asm)) {
+            plugin.OnLoad();
+            loadedPlugins.Add(plugin);
+          }
+        }
+        OnPluginLoaded(new PluginInfrastructureEventArgs(desc));
+        desc.Load();
+      }
+    }
+
+    /// <summary>
+    /// Runs the application declared in <paramref name="appInfo"/>.
+    /// This is a synchronous call. When the application is terminated all plugins are unloaded.
+    /// </summary>
+    /// <param name="appInfo">Description of the application to run</param>
+    internal void Run(ApplicationDescription appInfo) {
+      IApplication runnablePlugin = (IApplication)Activator.CreateInstance(appInfo.DeclaringAssemblyName, appInfo.DeclaringTypeName).Unwrap();
+      try {
+        runnablePlugin.Run();
+      }
+      finally {
+        // unload plugins in reverse order
+        foreach (var plugin in loadedPlugins.Reverse<IPlugin>()) {
+          plugin.OnUnload();
+        }
+        foreach (var desc in PluginDescriptionIterator.IterateDependenciesBottomUp(plugins.Where(x => x.PluginState != PluginState.Disabled))) {
+          desc.Unload();
+          OnPluginUnloaded(new PluginInfrastructureEventArgs(desc));
+        }
+      }
+    }
+
+    /// <summary>
+    /// Loads raw assemblies dynamically from a byte array
+    /// </summary>
+    /// <param name="assemblies">bytearray of all raw assemblies that should be loaded</param>
+    internal void LoadAssemblies(IEnumerable<byte[]> assemblies) {
+      foreach (byte[] asm in assemblies) {
+        Assembly loadedAsm = Assembly.Load(asm);
+        RegisterLoadedAssembly(loadedAsm);
+      }
+    }
+
+    // register assembly in the assembly cache for the AssemblyResolveEvent
+    private void RegisterLoadedAssembly(Assembly asm) {
+      loadedAssemblies.Add(asm.FullName, asm);
+      loadedAssemblies.Add(asm.GetName().Name, asm); // add short name
+    }
+
+    /// <summary>
+    /// Creates an instance of all types that are subtypes or the same type of the specified type and declared in <paramref name="plugin"/>
+    /// </summary>
+    /// <typeparam name="T">Most general type.</typeparam>
+    /// <returns>Enumerable of the created instances.</returns>
+    internal static IEnumerable<T> GetInstances<T>(IPluginDescription plugin) where T : class {
+      return from t in GetTypes(typeof(T), plugin, true)
+             select (T)Activator.CreateInstance(t);
+    }
+    /// <summary>
+    /// Creates an instance of all types declared in assembly <paramref name="asm"/> that are subtypes or the same type of the specified <typeparamref name="type"/>. 
+    /// </summary>
+    /// <typeparam name="T">Most general type.</typeparam>
+    /// <param name="asm">Declaring assembly.</param>
+    /// <returns>Enumerable of the created instances.</returns>
+    private static IEnumerable<T> GetInstances<T>(Assembly asm) where T : class {
+      return from t in GetTypes(typeof(T), asm, true)
+             select (T)Activator.CreateInstance(t);
+    }
+    /// <summary>
+    /// Creates an instance of all types that are subtypes or the same type of the specified type
+    /// </summary>
+    /// <typeparam name="T">Most general type.</typeparam>
+    /// <returns>Enumerable of the created instances.</returns>
+    internal static IEnumerable<T> GetInstances<T>() where T : class {
+      return from i in GetInstances(typeof(T))
+             select (T)i;
+    }
+
+    /// <summary>
+    /// Creates an instance of all types that are subtypes or the same type of the specified type
+    /// </summary>
+    /// <param name="type">Most general type.</param>
+    /// <returns>Enumerable of the created instances.</returns>
+    internal static IEnumerable<object> GetInstances(Type type) {
+      return (from t in GetTypes(type, true)
+              select Activator.CreateInstance(t)).ToList();
+    }
+
+    /// <summary>
+    /// Finds all types that are subtypes or equal to the specified type.
+    /// </summary>
+    /// <param name="type">Most general type for which to find matching types.</param>
+    /// <param name="onlyInstantiable">Return only types that are instantiable 
+    /// (interfaces, abstract classes... are not returned)</param>
+    /// <returns>Enumerable of the discovered types.</returns>
+    internal static IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable) {
+      return from asm in AppDomain.CurrentDomain.GetAssemblies()
+             from t in GetTypes(type, asm, onlyInstantiable)
+             select t;
+    }
+
+    /// <summary>
+    /// Finds all types that are subtypes or equal to the specified type if they are part of the given
+    /// <paramref name="pluginDescription"/>.
+    /// </summary>
+    /// <param name="type">Most general type for which to find matching types.</param>
+    /// <param name="pluginDescription">The plugin the subtypes must be part of.</param>
+    /// <param name="onlyInstantiable">Return only types that are instantiable 
+    /// (interfaces, abstract classes... are not returned)</param>
+    /// <returns>Enumerable of the discovered types.</returns>
+    internal static IEnumerable<Type> GetTypes(Type type, IPluginDescription pluginDescription, bool onlyInstantiable) {
+      PluginDescription pluginDesc = (PluginDescription)pluginDescription;
+      return from asm in AppDomain.CurrentDomain.GetAssemblies()
+             where !IsDynamicAssembly(asm)
+             where pluginDesc.AssemblyLocations.Any(location => location.Equals(Path.GetFullPath(asm.Location), StringComparison.CurrentCultureIgnoreCase))
+             from t in GetTypes(type, asm, onlyInstantiable)
+             select t;
+    }
+
+    private static bool IsDynamicAssembly(Assembly asm) {
+      return (asm is System.Reflection.Emit.AssemblyBuilder) || string.IsNullOrEmpty(asm.Location);
+    }
+
+    /// <summary>
+    /// Gets types that are assignable (same of subtype) to the specified type only from the given assembly.
+    /// </summary>
+    /// <param name="type">Most general type we want to find.</param>
+    /// <param name="assembly">Assembly that should be searched for types.</param>
+    /// <param name="onlyInstantiable">Return only types that are instantiable 
+    /// (interfaces, abstract classes...  are not returned)</param>
+    /// <returns>Enumerable of the discovered types.</returns>
+    private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable) {
+      return from t in assembly.GetTypes()
+             where type.IsAssignableFrom(t)
+             where onlyInstantiable == false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType)
+             select t;
+    }
+
+    private void OnPluginLoaded(PluginInfrastructureEventArgs e) {
+      if (PluginLoaded != null) PluginLoaded(this, e);
+    }
+
+    private void OnPluginUnloaded(PluginInfrastructureEventArgs e) {
+      if (PluginUnloaded != null) PluginUnloaded(this, e);
+    }
+
+    // infinite lease time
+    /// <summary>
+    /// Initializes the life time service with infinite lease time.
+    /// </summary>
+    /// <returns><c>null</c>.</returns>
+    public override object InitializeLifetimeService() {
+      return null;
+    }
+
+    #region IApplicationManager Members
+
+    IEnumerable<T> IApplicationManager.GetInstances<T>() {
+      return GetInstances<T>();
+    }
+
+    IEnumerable<object> IApplicationManager.GetInstances(Type type) {
+      return GetInstances(type);
+    }
+
+    IEnumerable<Type> IApplicationManager.GetTypes(Type type) {
+      return GetTypes(type, true);
+    }
+
+    IEnumerable<Type> IApplicationManager.GetTypes(Type type, bool onlyInstantiable) {
+      return GetTypes(type, onlyInstantiable);
+    }
+
+    IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin) {
+      return GetTypes(type, plugin, true);
+    }
+
+    IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable) {
+      return GetTypes(type, plugin, onlyInstantiable);
+    }
+
+
+    /// <summary>
+    /// Finds the plugin that declares the <paramref name="type">type</paramref>.
+    /// </summary>
+    /// <param name="type">The type of interest.</param>
+    /// <returns>The description of the plugin that declares the given type or null if the type has not been declared by a known plugin.</returns>
+    public IPluginDescription GetDeclaringPlugin(Type type) {
+      foreach (PluginDescription info in Plugins) {
+        if (info.AssemblyLocations.Contains(Path.GetFullPath(type.Assembly.Location))) return info;
+      }
+      return null;
+    }
+    #endregion
+  }
+}
Index: /trunk/sources/HeuristicLab.PluginInfrastructure/HeuristicLab.PluginInfrastructure.csproj
===================================================================
--- /trunk/sources/HeuristicLab.PluginInfrastructure/HeuristicLab.PluginInfrastructure.csproj	(revision 3246)
+++ /trunk/sources/HeuristicLab.PluginInfrastructure/HeuristicLab.PluginInfrastructure.csproj	(revision 3247)
@@ -172,4 +172,6 @@
     <Compile Include="BaseClasses\ApplicationBase.cs" />
     <Compile Include="BaseClasses\PluginBase.cs" />
+    <Compile Include="DefaultApplicationManager.cs" />
+    <Compile Include="LightweightApplicationManager.cs" />
     <Compile Include="Interfaces\IPluginFile.cs" />
     <Compile Include="Interfaces\IApplicationManager.cs" />
Index: /trunk/sources/HeuristicLab.PluginInfrastructure/LightweightApplicationManager.cs
===================================================================
--- /trunk/sources/HeuristicLab.PluginInfrastructure/LightweightApplicationManager.cs	(revision 3247)
+++ /trunk/sources/HeuristicLab.PluginInfrastructure/LightweightApplicationManager.cs	(revision 3247)
@@ -0,0 +1,151 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Security.Policy;
+using System.Reflection;
+using System.Diagnostics;
+using System.Security.Permissions;
+using System.Security;
+using System.Linq;
+using HeuristicLab.PluginInfrastructure.Manager;
+using System.IO;
+
+namespace HeuristicLab.PluginInfrastructure {
+
+  /// <summary>
+  /// Lightweight application manager is set as the application manager as long as the plugin infrastructure is uninitialized.
+  /// The list of plugins and applications is empty. The default application manager is necessary to provide the type discovery
+  /// functionality in unit tests.
+  /// </summary>
+  internal sealed class LightweightApplicationManager : IApplicationManager {
+
+    #region IApplicationManager Members
+    /// <summary>
+    /// Gets an empty list of plugins. (LightweightApplicationManager doesn't support plugin discovery)
+    /// </summary>
+    public IEnumerable<IPluginDescription> Plugins {
+      get { return new IPluginDescription[0]; }
+    }
+
+    /// <summary>
+    /// Gets an empty list of applications. (LightweightApplicationManager doesn't support application discovery)
+    /// </summary>
+    public IEnumerable<IApplicationDescription> Applications {
+      get { return new IApplicationDescription[0]; }
+    }
+
+    /// <summary>
+    /// Creates an instance of all types that are subtypes or the same type of the specified type
+    /// </summary>
+    /// <typeparam name="T">Most general type.</typeparam>
+    /// <returns>Enumerable of the created instances.</returns>
+    public IEnumerable<T> GetInstances<T>() where T : class {
+      return GetInstances(typeof(T)).Cast<T>();
+    }
+
+    /// <summary>
+    /// Creates an instance of all types that are subtypes or the same type of the specified type
+    /// </summary>
+    /// <param name="type">Most general type.</param>
+    /// <returns>Enumerable of the created instances.</returns>
+    public IEnumerable<object> GetInstances(Type type) {
+      return from t in GetTypes(type, true)
+             select Activator.CreateInstance(t);
+    }
+
+
+    /// <summary>
+    /// Finds all instantiable types that are subtypes or equal to the specified type.
+    /// </summary>
+    /// <param name="type">Most general type for which to find matching types.</param>
+    /// <remarks>Return only types that are instantiable 
+    /// (interfaces, abstract classes... are not returned)</remarks>
+    /// <returns>Enumerable of the discovered types.</returns>
+    public IEnumerable<Type> GetTypes(Type type) {
+      return GetTypes(type, true);
+    }
+
+    /// <summary>
+    /// Finds all types that are subtypes or equal to the specified type.
+    /// </summary>
+    /// <param name="type">Most general type for which to find matching types.</param>
+    /// <param name="onlyInstantiable">Return only types that are instantiable 
+    /// (interfaces, abstract classes... are not returned)</param>
+    /// <returns>Enumerable of the discovered types.</returns>
+    public IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable) {
+      return from asm in AppDomain.CurrentDomain.GetAssemblies()
+             from t in GetTypes(type, asm, onlyInstantiable)
+             select t;
+    }
+
+    /// <summary>
+    /// Gets types that are assignable (same of subtype) to the specified type only from the given assembly.
+    /// </summary>
+    /// <param name="type">Most general type we want to find.</param>
+    /// <param name="assembly">Assembly that should be searched for types.</param>
+    /// <param name="onlyInstantiable">Return only types that are instantiable 
+    /// (interfaces, abstract classes...  are not returned)</param>
+    /// <returns>Enumerable of the discovered types.</returns>
+    private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable) {
+      return from t in assembly.GetTypes()
+             where type.IsAssignableFrom(t)
+             where onlyInstantiable == false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType)
+             select t;
+    }
+
+    /// <summary>
+    /// Not supported by the LightweightApplicationManager
+    /// </summary>
+    /// <param name="type"></param>
+    /// <param name="plugin"></param>
+    /// <returns></returns>
+    /// <throws>NotSupportedException</throws>
+    public IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin) {
+      throw new NotSupportedException("LightweightApplicationManager doesn't support type discovery for plugins.");
+    }
+
+    /// <summary>
+    /// Not supported by the LightweightApplicationManager
+    /// </summary>
+    /// <param name="type"></param>
+    /// <param name="plugin"></param>
+    /// <param name="onlyInstantiable"></param>
+    /// <returns></returns>
+    /// <throws>NotSupportedException</throws>
+    public IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable) {
+      throw new NotSupportedException("LightweightApplicationManager doesn't support type discovery for plugins.");
+    }
+
+    /// <summary>
+    /// Not supported by the LightweightApplicationManager
+    /// </summary>
+    /// <param name="type"></param>
+    /// <returns></returns>
+    /// <throws>NotSupportedException</throws>
+    public IPluginDescription GetDeclaringPlugin(Type type) {
+      throw new NotSupportedException("LightweightApplicationManager doesn't support type discovery for plugins.");
+    }
+
+    #endregion
+  }
+}
Index: /trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginManager.cs
===================================================================
--- /trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginManager.cs	(revision 3246)
+++ /trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginManager.cs	(revision 3247)
@@ -125,7 +125,7 @@
         setup.PrivateBinPath = pluginDir;
         applicationDomain = AppDomain.CreateDomain(AppDomain.CurrentDomain.FriendlyName, null, setup);
-        Type applicationManagerType = typeof(ApplicationManager);
-        ApplicationManager applicationManager =
-          (ApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null, null);
+        Type applicationManagerType = typeof(DefaultApplicationManager);
+        DefaultApplicationManager applicationManager =
+          (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null, null);
         applicationManager.PluginLoaded += applicationManager_PluginLoaded;
         applicationManager.PluginUnloaded += applicationManager_PluginUnloaded;
Index: /trunk/sources/HeuristicLab.PluginInfrastructure/Sandboxing/SandboxManager.cs
===================================================================
--- /trunk/sources/HeuristicLab.PluginInfrastructure/Sandboxing/SandboxManager.cs	(revision 3246)
+++ /trunk/sources/HeuristicLab.PluginInfrastructure/Sandboxing/SandboxManager.cs	(revision 3247)
@@ -81,5 +81,5 @@
       // unrestricted appdomain 
       pset = new PermissionSet(PermissionState.Unrestricted);
-      #endregion 
+      #endregion
 
       AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
@@ -87,12 +87,12 @@
       setup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
       AppDomain applicationDomain = AppDomain.CreateDomain(name, AppDomain.CurrentDomain.Evidence, setup, pset, CreateStrongName(Assembly.GetExecutingAssembly()));
-      Type applicationManagerType = typeof(ApplicationManager);
-      ApplicationManager applicationManager =
-        (ApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null, null);
+      Type applicationManagerType = typeof(DefaultApplicationManager);
+      DefaultApplicationManager applicationManager =
+        (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null, null);
       ApplicationDescription[] apps = ApplicationManager.Manager.Applications.Cast<ApplicationDescription>().ToArray();
       PluginDescription[] plugins = ApplicationManager.Manager.Plugins.Cast<PluginDescription>().ToArray();
       applicationManager.PrepareApplicationDomain(apps, plugins);
       //if (files != null && files.Count() > 0)
-        //applicationManager.LoadAssemblies(files);
+      //applicationManager.LoadAssemblies(files);
       return applicationDomain;
     }
