using System; using System.Reflection; using Caliburn.Services; using StructureMap; using StructureMap.Configuration.DSL; namespace Caliburn.StructureMap { public class StructureMapAdapter : IContainer { #region IContainer Members public virtual object Resolve(Type type) { return ObjectFactory.GetInstance(type); } public virtual object Resolve(string key) { throw new NotSupportedException(); } public virtual object Resolve(Type serviceType, string key) { return ObjectFactory.GetNamedInstance(serviceType, key); } public virtual void LoadFrom(Assembly assembly) { foreach(Type type in assembly.GetTypes()) { if(typeof(Registry).IsAssignableFrom(type)) { Registry registry = (Registry)Activator.CreateInstance(type); StructureMapConfiguration.AddRegistry(registry); } } } #endregion } }