public void Execute(IWindsorContainer container)
        {
            var cfg = new NHibernateMappingGenerator(
                MsSqlConfiguration.MsSql2005
                .ConnectionString(builder =>
                                  builder.FromConnectionStringWithKey("default"))).Generate();

            var sessionFactory = cfg.BuildSessionFactory();

            container.Register(Component.For <Configuration>().Instance(cfg));

            container.AddFacility("factory", new FactorySupportFacility());
            var nhSession = Component.For <ISession>()
                            .UsingFactoryMethod(_ => sessionFactory.OpenSession());
            var repository = Component.For(typeof(IRepository <>))
                             .ImplementedBy(typeof(Repository <>));

            if (HttpContext.Current != null)
            {
                container.Register(
                    nhSession.LifeStyle.PerWebRequest,
                    repository.LifeStyle.PerWebRequest
                    );
            }
            else
            {
                container.Register(
                    nhSession.LifeStyle.PerThread,
                    repository.LifeStyle.PerThread
                    );
            }
        }
Beispiel #2
0
        public void SetUp()
        {
            NHibernateProfiler.Initialize();

            if (configuration == null)
            {
                configuration = new NHibernateMappingGenerator(SQLiteConfiguration.Standard.InMemory()).Generate();

                sessionFactory = configuration.BuildSessionFactory();
            }

            Session = sessionFactory.OpenSession();

            new SchemaExport(configuration).Execute(true, true, false, Session.Connection, Console.Out);
        }