using System;
using System.Collections.Generic;

namespace JamesKovacs.IoCArticle.IoCContainer.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 IEnumerable<T> ResolveAll<T>() {
            // N.B. A dictionary can only hold one instance object for each type T
            yield return (T)m_Types[typeof(T)];
        }

        public void Register<T>(object obj) {
            m_Types.Add(typeof(T), obj);            
        }
    }
}