public static void Initialize(ApplicationConfiguration config)
        {
            ApplicationConfiguration = config;

            SessionFactory = CreateSessionFactory();

            var assembly = System.Reflection.Assembly.Load("Web.Generics.IoC.StructureMap, Version=3.1.0.0, Culture=neutral, PublicKeyToken=36a1643a1b1a06e1");
            Type containerType = assembly.GetType("Web.Generics.Infrastructure.InversionOfControl.StructureMap.StructureMapInversionOfControlContainer");
            Container = (IInversionOfControlContainer)Activator.CreateInstance(containerType);

			Container = (IInversionOfControlContainer)Activator.CreateInstanceFrom(Path.Combine(config.ApplicationRootDir, "Web.Generics.IoC.StructureMap.dll"), "Web.Generics.Infrastructure.InversionOfControl.StructureMap.StructureMapInversionOfControlContainer").Unwrap();

			Container = (IInversionOfControlContainer)Activator.CreateInstanceFrom("Web.Generics.IoC.StructureMap.dll", "Web.Generics.Infrastructure.InversionOfControl.StructureMap.StructureMapInversionOfControlContainer").Unwrap();
			
            Container.RegisterType<IRepositoryContext, NHibernateRepositoryContext>();
            Container.RegisterType(typeof(IRepository<>), typeof(GenericNHibernateRepository<>));
            Container.RegisterDelayedInstance<ISession>(() => { return ApplicationManager.SessionFactory.GetCurrentSession(); });

            var mapper = config.InversionOfControl.MapperInstance;
            if (mapper != null)
            {
                mapper.DefineMappings(Container);
            }

			log4net.Config.XmlConfigurator.Configure();
        }
 public void DefineMappings(IInversionOfControlContainer container)
 {
     container.RegisterDelayedInstance<AppContext>(
             () =>
             {
                 if (!System.Web.HttpContext.Current.Items.Contains("DbContext"))
                 {
                     System.Web.HttpContext.Current.Items["DbContext"] = new AppContext();
                 }
                 return (AppContext)System.Web.HttpContext.Current.Items["DbContext"];
             }
         );
     container.RegisterType<IRepositorioDeClientes, ClienteDao>();
     container.RegisterType<IOrmPersister, EntityFrameworkPersister>();
 }