Exemplo n.º 1
0
 /// <summary>
 /// Initializes NHibernate. Adds the mappings based on the assembly, initializes the session factory and opens
 /// a long-running global session
 /// </summary>
 private void InitializeNHibernate()
 {
     NHibernateConfiguration.Configure();
     NHibernateConfiguration.AddAssembly(typeof(Entity).Assembly);
     new SchemaUpdate(NHibernateConfiguration).Execute(false, true);
     SessionFactory = NHibernateConfiguration.BuildSessionFactory();
     GlobalSession  = SessionFactory.OpenSession();
 }
Exemplo n.º 2
0
        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.Configure();

            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            DependencyResolverConfig.SetDependencyResolver();
            NHibernateConfiguration.BuildSessionFactory();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            ISessionFactory factory = NHibernateConfiguration.BuildSessionFactory();

            kernel.Bind <ISessionFactory>()
            .ToConstant(factory)
            .InSingletonScope();

            kernel.Bind <ISession>()
            .ToMethod(x => x.Kernel.Get <ISessionFactory>().OpenSession())
            .InRequestScope();

            //The first and last filter to run for each NHibernateController action
            kernel.BindFilter <NHibernateTransactionFilter>(FilterScope.Action, 0)
            .When((ctx, a) => ctx.Controller is NHibernateController);
        }
Exemplo n.º 4
0
        public ISessionFactory BuildSessionFactory()
        {
            if (IsConnectedToDatabase && _dataProviderInfo != null)
            {
                _configuration = new Configuration()
                                 .SetProperty(Environment.Dialect, _dataProviderInfo.NHibernateDialect)
                                 .SetProperty(Environment.ConnectionDriver, _dataProviderInfo.NHibernateConnectionDriver)
                                 .SetProperty(Environment.ConnectionString, Connection.ConnectionString)
                                 .AddAssembly(ApplicationProperties.PokerHandMappingAssemblyName)
                                 .AddAssembly(ApplicationProperties.DatabaseSetupMappingAssemblyName);

                return(NHibernateConfiguration.BuildSessionFactory());
            }

            return(null);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));

            Configuration nhCfg = null;

            using (var sf = NHibernateConfiguration.BuildSessionFactory(cfg =>
            {
                cfg.DataBaseIntegration(x =>
                {
                    x.ConnectionProvider <NHibernate.Connection.DriverConnectionProvider>();
                    x.Dialect <NHibernate.Dialect.MsSql2012Dialect>();
                    x.Driver <NHibernate.Driver.SqlClientDriver>();
                    x.ConnectionString = connectionString;
                    //x.LogSqlInConsole = true;
                    x.LogFormattedSql = true;
                    x.KeywordsAutoImport = NHibernate.Cfg.Hbm2DDLKeyWords.AutoQuote;
                });
                cfg.SetProperty(NHibernate.Cfg.Environment.DefaultSchema, "dbo");
            }, "../../Schemas", cfg => nhCfg = cfg))
            {
                Console.WriteLine("Connection: " + connectionString);

                if (Confirm("Connection looks good?"))
                {
                    if (Confirm("Drop and Create New Tables?"))
                    {
                        new SchemaExport(nhCfg).Create(true, true);
                    }

                    if (Confirm("Generate Test Data?"))
                    {
                        CreateTestData(sf);
                    }
                }
            }

            Console.WriteLine("Press Any Key to Exit");
            Console.ReadKey();
        }
Exemplo n.º 6
0
 public void BuildConfiguration()
 {
     m_SessionFactory = NHibernateConfiguration.BuildSessionFactory(configureByCode: ConfigureByCode, exposeCfg: BuildSchema);
 }