using Core.Providers;
using Data.Repositories;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.DataHandler;
using Microsoft.Practices.Unity;
using NLog;
using System;
using System.Data.Entity;
using System.Web.Http;
using Web.Controllers;
using Web.Models;
using Data.Entities;

namespace Web.App_Start
{
    /// <summary>
    /// Specifies the Unity configuration for the main container.
    /// </summary>
    public class UnityConfig
    {
        #region Unity Container
        private static Lazy<IUnityContainer> container = new Lazy<IUnityContainer>(() =>
        {
            var container = new UnityContainer();
            RegisterTypes(container);

            return container;
        });

        /// <summary>
        /// Gets the configured Unity container.
        /// </summary>
        public static IUnityContainer GetConfiguredContainer()
        {
            return container.Value;
        }
        #endregion

        /// <summary>Registers the type mappings with the Unity container.</summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to 
        /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            //container.RegisterType<DbContext, RealmContext>(new PerRequestLifetimeManager(), new InjectionConstructor());
            //container.RegisterType<ILogger>(new InjectionFactory(logger => LogManager.GetCurrentClassLogger()));

            container.RegisterType<IPlayerRepository, PlayerRepository>();
            container.RegisterType<IMapRepository, MapRepository>();
            
            container.RegisterType<ISecurityProvider, SecurityProvider>();
            container.RegisterType<IIntentProvider, IntentProvider>();
            
        }
    }
}
