Index: /branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs	(revision 1348)
+++ /branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs	(revision 1349)
@@ -1,6 +1,4 @@
 ﻿using System.Collections.Generic;
 using System;
-using System.Reflection;
-using System.Text;
 
 namespace Persistence {
@@ -64,18 +62,13 @@
     private readonly Dictionary<Type, Handler> handlers;
     private readonly Stack<IAccessibleObject> compositeStack;
-
-    private readonly Dictionary<Type, IFormatter> primitiveSerializers;
-    private readonly List<IDecomposer> customSerializers;
+    private readonly PersistenceConfiguration persistenceConfiguration;
 
     delegate void Thunk();
     private List<Thunk> finalFixes;
 
-    public DeSerializer() : this(
-      InterfaceInstantiatior.InstantiateAll<IFormatter>(),
-      InterfaceInstantiatior.InstantiateAll<IDecomposer>()) {}    
-
-    public DeSerializer(
-        IEnumerable<IFormatter> primitiveSerializers,
-        IEnumerable<IDecomposer> customSerializers) {
+    public DeSerializer() : this(PersistenceConfiguration.Instance) {}
+  
+    public DeSerializer(PersistenceConfiguration persistenceConfiguration) {
+      this.persistenceConfiguration = persistenceConfiguration;
       id2obj = new Dictionary<int, object>();
       compositeStack = new Stack<IAccessibleObject>();
@@ -86,10 +79,5 @@
                      {typeof (Reference), ReferenceHandler},
                      {typeof (Null), NullHandler}
-                   };
-      this.primitiveSerializers = new Dictionary<Type, IFormatter>();
-      foreach (IFormatter ps in primitiveSerializers) {
-        this.primitiveSerializers.Add(ps.Type, ps);
-      }
-      this.customSerializers = new List<IDecomposer>(customSerializers);
+                   };      
     }
 
@@ -108,5 +96,5 @@
       CompositeStart start = (CompositeStart)token;
       object instance;
-      if (FindCompoundSerializer(start.Type) != null) {
+      if (persistenceConfiguration.GetDecomposer(start.Type) != null) {
         instance = new ParentReference();
         compositeStack.Push(new CustomObject(instance));        
@@ -121,6 +109,6 @@
     }
     private void CompositeEndHandler(IParseToken token) {
-      CompositeEnd end = (CompositeEnd)token;
-      IDecomposer decomposer = FindCompoundSerializer(end.Type);
+      CompositeEnd end = (CompositeEnd)token;      
+      IDecomposer decomposer = persistenceConfiguration.GetDecomposer(end.Type);
       if (decomposer != null) {
         CustomObject customObject = (CustomObject)compositeStack.Pop();
@@ -135,15 +123,10 @@
         SetValue(end.Name, compositeObject.Obj);
       }
-    }
-    private IDecomposer FindCompoundSerializer(Type type) {
-      foreach (IDecomposer serializer in customSerializers) {
-        if (serializer.CanSerialize(type))
-          return serializer;
-      }
-      return null;
-    }
+    }    
     private void PrimitiveHandler(IParseToken token) {
       Primitive primitive = (Primitive)token;
-      object value = primitiveSerializers[primitive.Type].DeSerialize(primitive.SerializedValue);
+      object value = persistenceConfiguration
+        .GetFormatter(XmlFormat.Instance, primitive.Type)
+        .DeSerialize(primitive.SerializedValue);
       if ( ! value.GetType().IsValueType )
         id2obj[(int)primitive.Id] = value;
Index: /branches/New Persistence Exploration/Persistence/Persistence/Persistence.csproj
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/Persistence.csproj	(revision 1348)
+++ /branches/New Persistence Exploration/Persistence/Persistence/Persistence.csproj	(revision 1349)
@@ -54,4 +54,5 @@
   <ItemGroup>
     <Compile Include="DeSerializer.cs" />
+    <Compile Include="PersistenceConfiguration.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Serializer.cs" />
Index: /branches/New Persistence Exploration/Persistence/Persistence/PersistenceConfiguration.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/PersistenceConfiguration.cs	(revision 1349)
+++ /branches/New Persistence Exploration/Persistence/Persistence/PersistenceConfiguration.cs	(revision 1349)
@@ -0,0 +1,93 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace Persistence {
+
+  public class PersistenceConfiguration {
+
+    private readonly List<IFormatter> formatters;
+    private readonly List<IDecomposer> decomposers;
+    private readonly Dictionary<IFormat, Dictionary<Type, IFormatter>> formatterConfig;
+    private readonly Dictionary<Type, IDecomposer> decomposerCache;
+
+    private static PersistenceConfiguration instance;
+    public static PersistenceConfiguration Instance {
+      get {
+        if (instance == null) {
+          instance = new PersistenceConfiguration();
+          instance.DefaultConfig();
+        }
+        return instance;
+      }
+    }
+
+    public PersistenceConfiguration() {
+      formatters = new List<IFormatter>();
+      decomposers = new List<IDecomposer>();
+      formatterConfig = new Dictionary<IFormat, Dictionary<Type, IFormatter>>();
+      decomposerCache = new Dictionary<Type, IDecomposer>();
+    }
+
+    public 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));
+          } catch (MissingMethodException) {
+            Console.WriteLine("WARNING: Could not instantiate {0}", t.FullName);
+          }
+        }
+        if (t.GetInterface(typeof(IDecomposer).FullName) != null) {
+          try {
+            decomposers.Add((IDecomposer) Activator.CreateInstance(t, true));
+          } catch (MissingMethodException) {
+            Console.WriteLine("WARNING: Could not instantiate {0}", t.FullName);
+          }
+        }
+      }
+    }
+
+    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 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;
+    }
+
+  }
+  
+}
Index: /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs
===================================================================
--- /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1348)
+++ /branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1349)
@@ -10,28 +10,16 @@
     private readonly string rootName;
     private readonly Dictionary<object, int> obj2id;
-    private readonly Dictionary<Type, IFormatter> primitiveSerializers;
-    private readonly List<IDecomposer> compoundSerializers;
     private readonly Dictionary<Type, int> typeCache;
+    private readonly PersistenceConfiguration persistenceConfiguration;
 
-    public Serializer(object obj) :
-      this(obj,
-      InterfaceInstantiatior.InstantiateAll<IFormatter>(),
-      InterfaceInstantiatior.InstantiateAll<IDecomposer>()) {}
+    public Serializer(object obj) : this(obj, PersistenceConfiguration.Instance) {}
 
-    public Serializer(object obj,
-        IEnumerable<IFormatter> primitiveSerializers,
-        IEnumerable<IDecomposer> compoundSerializers) :
-      this(obj, primitiveSerializers, compoundSerializers, "ROOT") { }
+    public Serializer(object obj, PersistenceConfiguration persistenceConfiguration) :        
+      this(obj, persistenceConfiguration, "ROOT") { }
 
-    public Serializer(object obj,
-        IEnumerable<IFormatter> primitiveSerializers,
-        IEnumerable<IDecomposer> compoundSerializers, string rootName) {
+    public Serializer(object obj, PersistenceConfiguration persistenceConfiguration, string rootName) {
       this.obj = obj;
       this.rootName = rootName;
-      this.primitiveSerializers = new Dictionary<Type, IFormatter>();
-      foreach (IFormatter serializer in primitiveSerializers) {
-        this.primitiveSerializers.Add(serializer.Type, serializer);
-      }
-      this.compoundSerializers = new List<IDecomposer>(compoundSerializers);
+      this.persistenceConfiguration = persistenceConfiguration;      
       obj2id = new Dictionary<object, int> {{new object(), 0}};
       typeCache = new Dictionary<Type, int>();
@@ -79,9 +67,9 @@
       }
 
-      if (primitiveSerializers.ContainsKey(value.GetType())) {
-        
+      IFormatter formatter = persistenceConfiguration.GetFormatter(XmlFormat.Instance, value.GetType());     
+      if (formatter != null) {
         yield return new PrimitiveToken(
           accessor,
-          primitiveSerializers[value.GetType()].Serialize(value),
+          formatter.Serialize(value),          
           id);
         yield break;
@@ -89,8 +77,8 @@
       
       yield return new BeginToken(accessor, id);
-      IDecomposer custom = FindCompoundSerializer(value.GetType());
+      IDecomposer decomposer = persistenceConfiguration.GetDecomposer(value.GetType());      
 
-      if (custom != null) {
-        foreach (object o in custom.Serialize(value)) {
+      if (decomposer != null) {
+        foreach (object o in decomposer.Serialize(value)) {
           IEnumerator<ISerializationToken> iterator = Serialize(new DataMemberAccessor(o));
           while (iterator.MoveNext())
@@ -117,12 +105,5 @@
       yield return new EndToken(accessor, id);
     }
-
-    private IDecomposer FindCompoundSerializer(Type type) {
-      foreach (IDecomposer s in compoundSerializers) {
-        if (s.CanSerialize(type))
-          return s;
-      }
-      return null;
-    }
+    
   }
 }
