using System;
using System.IO;
using System.Reflection;
using CardReaderService.DefaultComponents;
using Interfaces;
using Ninject;

namespace CardReaderService
{
    public static class Configuration
    {
        public static StandardKernel ConfigureNinject()
        {
            var kernel = new StandardKernel();
            var ninjectConfigPath =
                new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().CodeBase), "NinjectConfig.xml"))
                    .LocalPath;
            if (File.Exists(ninjectConfigPath))
            {
                kernel.Load(ninjectConfigPath);
            }

            var logger = kernel.TryGet<ILogger>();
            if (logger == null)
            {
                kernel.Bind<ILogger>().To<DefaultLogger>();
                logger = kernel.Get<ILogger>();
            }
            logger.Fatal("test message - ninject stuff loaded.");
            logger.Trace("NinjectConfig.xml is here: {0}", ninjectConfigPath);
            logger.Trace("got logger: {0}", logger.GetType());

            return kernel;
        }
    }
}