using System.Collections.Generic;
using Castle.MicroKernel;
using Rhino.Commons;

namespace JamesKovacs.IoCArticle.IoCContainer.Infrastructure.Container {
    public class RhinoDependencyResolver : IDependencyResolver {
        private readonly RhinoContainer m_InnerContainer;

        public RhinoDependencyResolver(string configFile) {
            m_InnerContainer = new RhinoContainer(configFile);
        }

        public T Resolve<T>() {
            return m_InnerContainer.Resolve<T>();
        }

        public IEnumerable<T> ResolveAll<T>() {
            foreach(IHandler handler in m_InnerContainer.Kernel.GetHandlers(typeof(T))) {
                yield return (T)handler.Resolve(CreationContext.Empty);
            }
        }
    }
}