using System;
using System.Windows;
using Autofac;
using AutofacAndPrism.View;
using LeftModule;
using Microsoft.Practices.Prism.Modularity;
using MiddleModule;
using Prism.AutofacExtension;
using RightModule;

namespace AutofacAndPrism
{
  public class Bootstrapper : AutofacBootstrapper
  {
    protected override void ConfigureContainer(ContainerBuilder builder)
    {
      base.ConfigureContainer(builder);
      builder.RegisterType<Shell>();

      // register autofac module
      builder.RegisterModule<LeftModuleRegistry>();
      builder.RegisterModule<MiddleModuleRegistry>();
      builder.RegisterModule<RightModuleRegistry>();
    }

    protected override void ConfigureModuleCatalog()
    {
      base.ConfigureModuleCatalog();

      // register prism module
      Type typeNewsModule = typeof(LeftModule.LeftModule);
      ModuleCatalog.AddModule(new ModuleInfo(typeNewsModule.Name, typeNewsModule.AssemblyQualifiedName));
    }

    protected override DependencyObject CreateShell()
    {
      return Container.Resolve<Shell>();
    }

    protected override void InitializeShell()
    {
      base.InitializeShell();

      Application.Current.MainWindow = (Shell)this.Shell;
      Application.Current.MainWindow.Show();
    }
  }
}