using System;
using System.Collections.Generic;

namespace JamesKovacs.IoCArticle.DiyContainer.Infrastructure.Container {
    public class SimpleDependencyResolver : IDependencyResolver {
        private readonly Dictionary<Type, object> m_Types = new Dictionary<Type, object>();
        
        public T Resolve<T>() {
            return (T)m_Types[typeof(T)];
        }

        public void Register<T>(object obj) {
            if(obj is T == false) {
                throw new InvalidOperationException(string.Format("The supplied instance does not implement {0}", typeof(T).FullName));
            }
            m_Types.Add(typeof(T), obj);            
        }
    }
}