Beispiel #1
0
 public static Configuration AddConfiguration(
     string factoryKey, ISessionFactory sessionFactory, Configuration cfg, string validatorCfgFile)
 {
     CheckSharpArch.Require(
         !SessionFactories.ContainsKey(factoryKey),
         "A session factory has already been configured with the key of " + factoryKey);
     SessionFactories.Add(factoryKey, sessionFactory);
     return(cfg);
 }
Beispiel #2
0
        /// <summary>
        ///     Used to get the current NHibernate session associated with a factory key; i.e., the key
        ///     associated with an NHibernate session factory for a specific database.
        ///
        ///     If you're only communicating with one database, you should call <see cref = "Current" /> instead,
        ///     although you're certainly welcome to call this if you have the factory key available.
        /// </summary>
        public static ISession CurrentFor(string factoryKey)
        {
            CheckSharpArch.Require(!string.IsNullOrEmpty(factoryKey), "factoryKey may not be null or empty");
            CheckSharpArch.Require(Storage != null, "An ISessionStorage has not been configured");
            CheckSharpArch.Require(
                SessionFactories.ContainsKey(factoryKey),
                "An ISessionFactory does not exist with a factory key of " + factoryKey);
            var session = Storage.GetSessionForKey(factoryKey);

            if (session == null)
            {
                session = SessionFactories[factoryKey].OpenSession();
                Storage.SetSessionForKey(factoryKey, session);
            }
            return(session);
        }
Beispiel #3
0
 public static void InitStorage(ISessionStorage storage)
 {
     CheckSharpArch.Require(storage != null, "storage mechanism was null but must be provided");
     CheckSharpArch.Require(Storage == null, "A storage mechanism has already been configured for this application");
     Storage = storage;
 }