Пример #1
0
        static UnitOfWork()
        {
            var rootWebConfig    = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/");
            var connectionString = rootWebConfig.ConnectionStrings.ConnectionStrings["GTSDB"].ConnectionString;
            var connection       = MsSqlConfiguration.MsSql2012.ShowSql().ConnectionString(connectionString);

            ISaveOrUpdateEventListener[] stack          = new ISaveOrUpdateEventListener[] { new BusinessRuleSaveOrUpdateEventListener(), new NHibernate.Event.Default.DefaultSaveOrUpdateEventListener() };
            IPreUpdateEventListener[]    preUpdateStack = new IPreUpdateEventListener[] { new BusinessRulePreUpdateEventListener() };

            // Initialise singleton instance of ISessionFactory, static constructors are only executed once during the
            // application lifetime - the first time the UnitOfWork class is used
            _sessionFactory = Fluently.Configure()
                              .Database(connection)
                              .Mappings(m => m.FluentMappings.AddFromAssemblyOf <UnitOfWork>()) // load all mappings from this namespace
                              .ExposeConfiguration(config =>
            {
                new SchemaUpdate(config).Execute(false, true);

                config.EventListeners.SaveEventListeners         = stack;
                config.EventListeners.SaveOrUpdateEventListeners = stack;
                config.EventListeners.PreUpdateEventListeners    = preUpdateStack;
                config.EventListeners.UpdateEventListeners       = stack;
            })
                              .BuildSessionFactory();

            _logger = new Logger("UnitOfWork");
            _logger.LogInfo("Using connection string: " + connectionString);
        }
 public IdentifiableEventListeners(ISaveOrUpdateEventListener defaultEventHandler)
 {
     if (defaultEventHandler == null) throw new ArgumentException("defaultEventHandler");
     Default = defaultEventHandler;
 }