Index: /branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs	(revision 1357)
+++ /branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs	(revision 1358)
@@ -77,5 +77,5 @@
     private readonly Dictionary<Type, Handler> handlers;
     private readonly Stack<IAccessibleObject> compositeStack;
-    private readonly PersistenceConfiguration persistenceConfiguration;
+    private readonly Configuration configuration;
     private readonly Dictionary<int, Type> typeIds;    
     private List<Thunk> finalFixes;
@@ -83,6 +83,6 @@
     public DeSerializer(
       IEnumerable<KeyValuePair<string, int>> typeCache,
-      PersistenceConfiguration persistenceConfiguration) {
-      this.persistenceConfiguration = persistenceConfiguration;
+      Configuration configuration) {
+      this.configuration = configuration;
       id2obj = new Dictionary<int, object>();
       compositeStack = new Stack<IAccessibleObject>();
@@ -116,5 +116,5 @@
       object instance;      
       Type type = typeIds[(int)start.TypeId];
-      if (persistenceConfiguration.GetDecomposer(type) != null) {
+      if (configuration.GetDecomposer(type) != null) {
         instance = new ParentReference();
         compositeStack.Push(new CustomObject(instance));        
@@ -132,5 +132,5 @@
       EndToken end = (EndToken)token;
       Type type = typeIds[(int)end.TypeId];
-      IDecomposer decomposer = persistenceConfiguration.GetDecomposer(type);
+      IDecomposer decomposer = configuration.GetDecomposer(type);
       if (decomposer != null) {
         CustomObject customObject = (CustomObject)compositeStack.Pop();
@@ -150,6 +150,6 @@
       PrimitiveToken primitive = (PrimitiveToken)token;
       Type type = typeIds[(int)primitive.TypeId];
-      object value = persistenceConfiguration
-        .GetFormatter(XmlFormat.Instance, type)
+      object value = configuration
+        .GetFormatter(type)
         .DeSerialize(primitive.SerialData);
       if ( ! value.GetType().IsValueType )
Index: /branches/New Persistence Exploration/Persistence/Persistence/PersistenceConfiguration.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/PersistenceConfiguration.cs	(revision 1357)
+++ /branches/New Persistence Exploration/Persistence/Persistence/PersistenceConfiguration.cs	(revision 1358)
@@ -6,17 +6,57 @@
 namespace HeuristicLab.Persistence {
 
-  public class PersistenceConfiguration {
+  public class Configuration {
 
-    private readonly List<IFormatter> formatters;
+    private readonly Dictionary<Type, IFormatter> formatters;
     private readonly List<IDecomposer> decomposers;
-    private readonly Dictionary<IFormat, Dictionary<Type, IFormatter>> formatterConfig;
     private readonly Dictionary<Type, IDecomposer> decomposerCache;
+    public readonly IFormat Format;
 
-    private static PersistenceConfiguration instance;
-    public static PersistenceConfiguration Instance {
+    public Configuration(Dictionary<Type, IFormatter> formatters, IEnumerable<IDecomposer> decomposers) {      
+      this.formatters = new Dictionary<Type, IFormatter>();
+      foreach ( var pair in formatters ) {
+        if (Format == null) {
+          Format = pair.Value.Format;
+        } else if (pair.Value.Format != Format ) {
+          throw new ArgumentException("All formatters must have the same IFormat.");
+        }
+        this.formatters.Add(pair.Key, pair.Value);
+      }
+      this.decomposers = new List<IDecomposer>(decomposers);
+      decomposerCache = new Dictionary<Type, IDecomposer>();      
+    }    
+
+    public IFormatter GetFormatter(Type type) {
+      IFormatter formatter;
+      formatters.TryGetValue(type, out formatter);
+      return formatter;
+    }
+
+    public IDecomposer GetDecomposer(Type type) {
+      IDecomposer decomposer;
+      decomposerCache.TryGetValue(type, out decomposer);
+      if (decomposer != null)
+        return decomposer;
+      foreach (IDecomposer d in decomposers) {
+        if (d.CanSerialize(type)) {
+          decomposerCache.Add(type, d);
+          return d;
+        }
+      }
+      return null;
+    }
+    
+  }
+
+  public class ConfigurationService {
+
+    private readonly Dictionary<IFormat, List<IFormatter>> formatters;
+    private readonly List<IDecomposer> decomposers;
+    
+    private static ConfigurationService instance;
+    public static ConfigurationService Instance {
       get {
         if (instance == null) {
-          instance = new PersistenceConfiguration();
-          instance.DefaultConfig();
+          instance = new ConfigurationService();
         }
         return instance;
@@ -24,21 +64,32 @@
     }
 
-    public PersistenceConfiguration() {
-      formatters = new List<IFormatter>();
+    public ConfigurationService() {
+      formatters = new Dictionary<IFormat, List<IFormatter>>();
       decomposers = new List<IDecomposer>();
-      formatterConfig = new Dictionary<IFormat, Dictionary<Type, IFormatter>>();
-      decomposerCache = new Dictionary<Type, IDecomposer>();
+      Reset();
     }
 
-    public void DiscoverFrom(Assembly a) {
-      foreach ( Type t in a.GetTypes() ) {
-        if (t.GetInterface(typeof(IFormatter).FullName) != null) {
+    public void Reset() {
+      Assembly defaultAssembly = Assembly.GetExecutingAssembly();
+      DiscoverFrom(defaultAssembly);
+      foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
+        if ( a != defaultAssembly )
+          DiscoverFrom(a);
+    }
+
+    protected void DiscoverFrom(Assembly a) {
+      foreach (Type t in a.GetTypes()) {
+        if (t.GetInterface(typeof (IFormatter).FullName) != null) {
           try {
-            formatters.Add((IFormatter) Activator.CreateInstance(t, true));
+            IFormatter formatter = (IFormatter) Activator.CreateInstance(t, true);
+            if ( ! formatters.ContainsKey(formatter.Format) ) {
+              formatters.Add(formatter.Format, new List<IFormatter>());
+            }
+            formatters[formatter.Format].Add(formatter);
           } catch (MissingMethodException) {
             Console.WriteLine("WARNING: Could not instantiate {0}", t.FullName);
-          }
+          }          
         }
-        if (t.GetInterface(typeof(IDecomposer).FullName) != null) {
+        if (t.GetInterface(typeof (IDecomposer).FullName) != null) {
           try {
             decomposers.Add((IDecomposer) Activator.CreateInstance(t, true));
@@ -50,42 +101,11 @@
     }
 
-    public void DiscoverAll() {      
-      DiscoverFrom(Assembly.GetAssembly(this.GetType()));
-      foreach ( Assembly a in AppDomain.CurrentDomain.GetAssemblies() )
-        DiscoverFrom(a);
-    }
-
-    public void DefaultConfig() {
-      DiscoverAll();
-      foreach ( IFormatter f in formatters ) {
-        if ( ! formatterConfig.ContainsKey(f.Format) )
-          formatterConfig.Add(f.Format, new Dictionary<Type, IFormatter>());
-        if (!formatterConfig[f.Format].ContainsKey(f.Type))
-          formatterConfig[f.Format][f.Type] = f;
+    public Configuration GetDefaultConfig(IFormat format) {
+      Dictionary<Type, IFormatter> formatterConfig = new Dictionary<Type, IFormatter>();
+      foreach ( IFormatter f in formatters[format] ) {
+        if ( ! formatterConfig.ContainsKey(f.Type) )
+          formatterConfig.Add(f.Type, f);
       }
-    }    
-
-    public IFormatter GetFormatter(IFormat format, Type type) {
-      Dictionary<Type, IFormatter> typeMap;
-      formatterConfig.TryGetValue(format, out typeMap);
-      if ( typeMap == null )
-        return null;
-      IFormatter formatter;
-      typeMap.TryGetValue(type, out formatter);
-      return formatter;
-    }
-
-    public IDecomposer GetDecomposer(Type type) {
-      IDecomposer decomposer;
-      decomposerCache.TryGetValue(type, out decomposer);
-      if (decomposer != null)
-        return decomposer;
-      foreach ( IDecomposer d in decomposers ) {
-        if (d.CanSerialize(type)) {
-          decomposerCache.Add(type, d);
-          return d;
-        }
-      }
-      return null;
+      return new Configuration(formatterConfig, decomposers);
     }
 
Index: /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1357)
+++ /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1358)
@@ -13,5 +13,5 @@
     private readonly Dictionary<object, int> obj2id;
     private readonly Dictionary<Type, int> typeCache;
-    private readonly PersistenceConfiguration persistenceConfiguration;
+    private readonly Configuration configuration;
 
     public Dictionary<string, int> TypeCache {
@@ -24,11 +24,11 @@
     }
 
-    public Serializer(object obj, PersistenceConfiguration persistenceConfiguration) :        
-      this(obj, persistenceConfiguration, "ROOT") { }
+    public Serializer(object obj, Configuration configuration) :        
+      this(obj, configuration, "ROOT") { }
 
-    public Serializer(object obj, PersistenceConfiguration persistenceConfiguration, string rootName) {
+    public Serializer(object obj, Configuration configuration, string rootName) {
       this.obj = obj;
       this.rootName = rootName;
-      this.persistenceConfiguration = persistenceConfiguration;      
+      this.configuration = configuration;      
       obj2id = new Dictionary<object, int> {{new object(), 0}};
       typeCache = new Dictionary<Type, int>();
@@ -62,8 +62,8 @@
         obj2id.Add(value, (int)id);
       }
-      IFormatter formatter = persistenceConfiguration.GetFormatter(XmlFormat.Instance, value.GetType());
+      IFormatter formatter = configuration.GetFormatter(value.GetType());
       if (formatter != null)
         return PrimitiveEnumeration(accessor.Name, typeId, formatter.Serialize(value), id);
-      IDecomposer decomposer = persistenceConfiguration.GetDecomposer(value.GetType()); 
+      IDecomposer decomposer = configuration.GetDecomposer(value.GetType()); 
       if (decomposer != null)
         return CompositeEnumeration(accessor.Name, decomposer.Serialize(value), id, typeId);            
Index: /branches/New Persistence Exploration/Persistence/Test/NewSerializationTest.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Test/NewSerializationTest.cs	(revision 1357)
+++ /branches/New Persistence Exploration/Persistence/Test/NewSerializationTest.cs	(revision 1358)
@@ -145,5 +145,5 @@
   public class NewSerializationTest {
 
-    public static void Test1() {
+    public static void Test1() {      
       Root r = new Root();
       r.selfReferences = new List<Root> {r, r};
@@ -152,5 +152,5 @@
       r.dict.Add("two", 2);
       r.dict.Add("three", 3);
-      Serializer s = new Serializer(r, PersistenceConfiguration.Instance);        
+      Serializer s = new Serializer(r, ConfigurationService.Instance.GetDefaultConfig(XmlFormat.Instance));        
       Persistence.XmlFormatter xmlFormatter = new XmlFormatter();
       StreamWriter writer = new StreamWriter("test.xml");
@@ -171,5 +171,5 @@
       DeSerializer deSerializer = new DeSerializer(
         XmlParser.ParseTypeCache(new StreamReader("test-types.xml")),
-        PersistenceConfiguration.Instance);        
+        ConfigurationService.Instance.GetDefaultConfig(XmlFormat.Instance));        
       object o = deSerializer.DeSerialize(parser);
       Root t = CloningFactory.DefaultClone(r);
@@ -179,5 +179,6 @@
     public static void Test2() {
       Manager m = new Manager();      
-      Serializer s = new Serializer(m, PersistenceConfiguration.Instance);
+      Serializer s = new Serializer(m,
+        ConfigurationService.Instance.GetDefaultConfig(XmlFormat.Instance));
       Persistence.XmlFormatter xmlFormatter = new XmlFormatter();
       StreamWriter writer = new StreamWriter("test2.xml");
@@ -191,5 +192,5 @@
       DeSerializer deSerializer = new DeSerializer(
         XmlParser.ParseTypeCache(new StreamReader("test-types.xml")),
-        PersistenceConfiguration.Instance);              
+        ConfigurationService.Instance.GetDefaultConfig(XmlFormat.Instance));        
       object o = deSerializer.DeSerialize(parser);
       Manager n = CloningFactory.DefaultClone(m);
