using System.Collections.Generic;
using Castle.MicroKernel;
using Castle.Windsor;

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

        public WindsorDependencyResolver(string xmlFile) {
            m_InnerContainer = new WindsorContainer(xmlFile);
        }

        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);
            }
        }
    }
}