using System;
using System.Reflection;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using IoCConcepts.Domain;
using IoCConcepts.Repositories;
using IoCConcepts.Services;

namespace IoCConcepts
{
    class Program
    {
        static void Main(string[] args) {
            var container = new WindsorContainer();
            container.Register(
                Component.For<CustomerController>()
                         .LifeStyle.PerWebRequest,
//                Component.For<ICustomerService>()
//                         .ImplementedBy<CustomerService>(),
//                Component.For<ICustomerRepository>()
//                    .ImplementedBy<CustomerRepository>(),
//                Component.For(typeof(IRepository<>))
//                    .ImplementedBy(typeof(Repository<>))
                // IRepository<> open generic type
                // IRepository<Customer> closed generic type

                AllTypes.FromAssembly(typeof(CustomerService).Assembly)
                        .Where(x => x.Namespace == "IoCConcepts.Services").WithService.FirstInterface()
                        .Configure(x => x.LifeStyle.Transient),
                AllTypes.FromAssembly(Assembly.GetExecutingAssembly())
                        .Where(x => x.Namespace == "IoCConcepts.Repositories").WithService.FirstInterface()
            );
            var childContainer = new WindsorContainer(container, null);

            var service = container.Resolve<CustomerService>();
            var service2 = container.Resolve<CustomerService>();
            Console.WriteLine(service != service2 ? "Different" : "Same");

//            var customer = container.Resolve<Customer>();
//            Console.WriteLine(customer != null ? "A Customer!!!" : "No customer");
            Console.WriteLine("Press <ENTER> to exit...");
            Console.ReadLine();
        }
    }
}
