﻿using Ninject;
using System;
using System.Linq;

namespace SimpleRepository.Ninject
{
    public class NinjectObjectBuilder : IBuildRepositoryObjects, IConfigureRepositoryObjects
    {
        readonly IKernel _kernel;

        public NinjectObjectBuilder(IKernel kernel)
        {
            _kernel = kernel;
        }

        public object[] BuildAll(Type objectType)
        {
            return _kernel.GetAll(objectType).ToArray();
        }
        
        public object Build(Type objectType)
        {
            return _kernel.Get(objectType);
        }

        public void ConfigureRepositoryStrategy<TRepositoryStrategy>() where TRepositoryStrategy : IRepositoryStrategy
        {
            _kernel
                .Bind<TRepositoryStrategy>()
                .ToSelf()
                .InSingletonScope();
        }
    }
}
