public static void Configure(IUnityContainer container)
        {
            var settings      = container.Resolve <Settings>();
            var configuration = new Configuration().DataBaseIntegration(db =>
            {
                db.ConnectionString = settings.ConnectionString;
                db.Dialect <MsSql2008Dialect>();
            });

            configuration.CurrentSessionContext <CurrentSessionContext>();
            var mapper = new ModelMapper();

            Type[] myTypes = Assembly.GetExecutingAssembly().GetExportedTypes();
            mapper.AddMappings(myTypes);
            var mapping = new NHibernateMapper().Map();

            configuration
            .AddMapping(mapping);
            configuration.EventListeners.PreInsertEventListeners = new IPreInsertEventListener[] { new CoordinatesInsertEventListener() };
            configuration.EventListeners.PreUpdateEventListeners = new IPreUpdateEventListener[] { new CoordinatesUpdateEventListener() };

            var sessionFactory = configuration.BuildSessionFactory();

            container.RegisterInstance(configuration);
            container.RegisterInstance(sessionFactory);

            if (settings.RebuildDatabase)
            {
                var schema = new SchemaExport(configuration);
                schema.Create(false, true);
            }
        }
Beispiel #2
0
        public static Configuration Configure()
        {
            Configuration cfg = new Configuration()
                                .DataBaseIntegration(db =>
            {
                db.ConnectionString = @"Server = (localdb)\mssqllocaldb; Database = Nardada; Trusted_Connection = True;";
                db.Dialect <MsSql2008Dialect>();
            });

            var mapper = new ModelMapper();

            Type[] myTypes = Assembly.GetExecutingAssembly().GetExportedTypes();
            mapper.AddMappings(myTypes);

            HbmMapping mapping = new NHibernateMapper().Map();

            cfg.AddMapping(mapping);

            return(cfg);
        }