Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultSessionManager"/> class.
        /// </summary>
        /// <param name="sessionStore">The session store.</param>
        /// <param name="kernel">The kernel.</param>
        /// <param name="factoryResolver">The factory resolver.</param>
        public DefaultSessionManager(ISessionStore sessionStore, IKernel kernel, ISessionFactoryResolver factoryResolver)
        {
            this.kernel          = kernel;
            this.sessionStore    = sessionStore;
            this.factoryResolver = factoryResolver;

            Logger = NullLogger.Instance;
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="DefaultSessionManager"/> class.
		/// </summary>
		/// <param name="sessionStore">The session store.</param>
		/// <param name="kernel">The kernel.</param>
		/// <param name="factoryResolver">The factory resolver.</param>
		public DefaultSessionManager(ISessionStore sessionStore, IKernel kernel, ISessionFactoryResolver factoryResolver)
		{
			this.kernel = kernel;
			this.sessionStore = sessionStore;
			this.factoryResolver = factoryResolver;

			Logger = NullLogger.Instance;
		}
		public TaskAwareSessionManager(ISessionFactoryResolver sessionFactoryResolver)
			: base(sessionFactoryResolver)
		{
			// Keep track of the task that was current when this object was created.
			// For this reason this class needs to be registered as Transient with the
			// Castle container.
			_currentTaskAtCreation = UITask.Current;
			if (_currentTaskAtCreation != null)
			{
				// When the task completes, forget about it.
				_currentTaskAtCreation.TaskComplete += (sender, args) => _currentTaskAtCreation = null;
			}
		}
        /// <summary>
        /// Configures the facility.
        /// </summary>
        protected void ConfigureFacility()
        {
            ISessionFactoryResolver sessionFactoryResolver = Kernel.Resolve <ISessionFactoryResolver>();

            ConfigureReflectionOptimizer();

            bool firstFactory = true;

            foreach (var factoryConfig in facilitySettingConfig.Factories)
            {
                ConfigureFactories(factoryConfig, sessionFactoryResolver, firstFactory);
                firstFactory = false;
            }
        }
Esempio n. 5
0
        protected void ConfigureFacility()
        {
            ISessionFactoryResolver sessionFactoryResolver = (ISessionFactoryResolver)
                                                             Kernel[typeof(ISessionFactoryResolver)];

            ConfigureReflectionOptimizer(FacilityConfig);

            bool firstFactory = true;

            foreach (IConfiguration factoryConfig in FacilityConfig.Children)
            {
                if (!"factory".Equals(factoryConfig.Name))
                {
                    throw new ConfigurationErrorsException("Unexpected node " + factoryConfig.Name);
                }

                ConfigureFactories(factoryConfig, sessionFactoryResolver, firstFactory);

                firstFactory = false;
            }
        }
Esempio n. 6
0
		public SessionManager(ISessionFactoryResolver sessionFactoryResolver)
		{
			_sessionFactoryResolver = Verify.ArgumentNotNull(sessionFactoryResolver, "sessionFactoryResolver");
		}
		/// <summary>
		/// Configures the factories.
		/// </summary>
		/// <param name="config">The config.</param>
		/// <param name="sessionFactoryResolver">The session factory resolver.</param>
		/// <param name="firstFactory">if set to <c>true</c> [first factory].</param>
		protected void ConfigureFactories(IConfiguration config, 
			ISessionFactoryResolver sessionFactoryResolver, bool firstFactory)
		{
			String id = config.Attributes[SessionFactoryIdConfigurationKey];

			if (string.IsNullOrEmpty(id))
			{
				String message = "You must provide a " + 
					"valid 'id' attribute for the 'factory' node. This id is used as key for " + 
					"the ISessionFactory component registered on the container";

				throw new ConfigurationErrorsException(message);
			}

			String alias = config.Attributes[SessionFactoryAliasConfigurationKey];

			if (!firstFactory && (string.IsNullOrEmpty(alias)))
			{
				String message = "You must provide a " + 
					"valid 'alias' attribute for the 'factory' node. This id is used to obtain " + 
					"the ISession implementation from the SessionManager";

				throw new ConfigurationErrorsException(message);
			}
			else if (string.IsNullOrEmpty(alias))
			{
				alias = Constants.DefaultAlias;
			}
			string configurationBuilderType = config.Attributes[ConfigurationBuilderConfigurationKey];
			string configurationbuilderKey = string.Format(ConfigurationBuilderForFactoryFormat, id);
			IConfigurationBuilder configBuilder;
			if (string.IsNullOrEmpty(configurationBuilderType))
			{
				configBuilder = Kernel.Resolve<IConfigurationBuilder>();
			}
			else
			{
                Kernel.Register(Component.For<IConfigurationBuilder>().ImplementedBy(Type.GetType(configurationBuilderType)).Named(configurationbuilderKey));
				configBuilder = Kernel.Resolve<IConfigurationBuilder>(configurationbuilderKey);
			}
			
			var cfg = configBuilder.GetConfiguration(config);

			// Registers the Configuration object
		    Kernel.Register(Component.For<NHibernate.Cfg.Configuration>().Instance(cfg).Named(String.Format("{0}.cfg", id)));

			// If a Session Factory level interceptor was provided, we use it

			if (Kernel.HasComponent(SessionInterceptorKey))
			{
				cfg.Interceptor = (IInterceptor)Kernel[SessionInterceptorKey];
			}
			// Registers the ISessionFactory as a component

			//var model = new ComponentModel(id, typeof(ISessionFactory), typeof(Empty));
			//model.LifestyleType = LifestyleType.Singleton;
			//model.ExtendedProperties[Constants.SessionFactoryConfiguration] = cfg;
			//model.CustomComponentActivator = typeof (SessionFactoryActivator);
			//Kernel.AddCustomComponent(model);
			Kernel.Register(Component
			                	.For<ISessionFactory>()
			                	.Named(id)
			                	.Activator<SessionFactoryActivator>()
			                	.ExtendedProperties(Property.ForKey(Constants.SessionFactoryConfiguration).Eq(cfg))
			                	.LifeStyle.Singleton);

			sessionFactoryResolver.RegisterAliasComponentIdMapping(alias, id);
		}
Esempio n. 8
0
        /// <summary>
        /// Configures the factories.
        /// </summary>
        /// <param name="config">The config.</param>
        /// <param name="sessionFactoryResolver">The session factory resolver.</param>
        /// <param name="firstFactory">if set to <c>true</c> [first factory].</param>
        protected void ConfigureFactories(NHibernateFactoryConfiguration config, ISessionFactoryResolver sessionFactoryResolver, bool firstFactory)
        {
            String id = config.Id;

            if (string.IsNullOrEmpty(id))
            {
                const string message = "You must provide a " +
                                       "valid 'id' attribute for the 'factory' node. This id is used as key for " +
                                       "the ISessionFactory component registered on the container";

                throw new ConfigurationErrorsException(message);
            }

            String alias = config.Alias;

            if (!firstFactory && (string.IsNullOrEmpty(alias)))
            {
                const string message = "You must provide a " +
                                       "valid 'alias' attribute for the 'factory' node. This id is used to obtain " +
                                       "the ISession implementation from the SessionManager";

                throw new ConfigurationErrorsException(message);
            }

            if (string.IsNullOrEmpty(alias))
            {
                alias = Constants.DefaultAlias;
            }

            string configurationBuilderType = config.ConfigurationBuilderType;
            string configurationbuilderKey  = string.Format(ConfigurationBuilderForFactoryFormat, id);
            IConfigurationBuilder configBuilder;

            if (string.IsNullOrEmpty(configurationBuilderType))
            {
                configBuilder = Kernel.Resolve <IConfigurationBuilder>();
            }
            else
            {
                Kernel.Register(
                    Component.For <IConfigurationBuilder>().ImplementedBy(Type.GetType(configurationBuilderType)).Named(
                        configurationbuilderKey));
                configBuilder = Kernel.Resolve <IConfigurationBuilder>(configurationbuilderKey);
            }

            var cfg = configBuilder.GetConfiguration(config.GetConfiguration());

            // Registers the Configuration object
            Kernel.Register(Component.For <NHibernate.Cfg.Configuration>().Instance(cfg).Named(String.Format("{0}.cfg", id)));

            // If a Session Factory level interceptor was provided, we use it
            if (Kernel.HasComponent(SessionInterceptorKey))
            {
                cfg.Interceptor = Kernel.Resolve <IInterceptor>(SessionInterceptorKey);
            }

            // Registers the ISessionFactory as a component
            Kernel.Register(Component
                            .For <ISessionFactory>()
                            .Named(id)
                            .Activator <SessionFactoryActivator>()
                            .ExtendedProperties(Property.ForKey(Constants.SessionFactoryConfiguration).Eq(cfg))
                            .LifeStyle.Singleton);

            sessionFactoryResolver.RegisterAliasComponentIdMapping(alias, id);
        }
Esempio n. 9
0
		/// <summary>
		/// Configures the factories.
		/// </summary>
		/// <param name="config">The config.</param>
		/// <param name="sessionFactoryResolver">The session factory resolver.</param>
		/// <param name="firstFactory">if set to <c>true</c> [first factory].</param>
		protected void ConfigureFactories(IConfiguration config, 
			ISessionFactoryResolver sessionFactoryResolver, bool firstFactory)
		{
			String id = config.Attributes["id"];

			if (string.IsNullOrEmpty(id))
			{
				String message = "You must provide a " + 
					"valid 'id' attribute for the 'factory' node. This id is used as key for " + 
					"the ISessionFactory component registered on the container";

				throw new ConfigurationErrorsException(message);
			}

			String alias = config.Attributes["alias"];

			if (!firstFactory && (string.IsNullOrEmpty(alias)))
			{
				String message = "You must provide a " + 
					"valid 'alias' attribute for the 'factory' node. This id is used to obtain " + 
					"the ISession implementation from the SessionManager";

				throw new ConfigurationErrorsException(message);
			}
			else if (string.IsNullOrEmpty(alias))
			{
				alias = Constants.DefaultAlias;
			}

			var configurationBuilder = Kernel.Resolve<IConfigurationBuilder>();
			var cfg = configurationBuilder.GetConfiguration(config);

			// Registers the Configuration object
			Kernel.AddComponentInstance( String.Format("{0}.cfg", id), cfg );

			// If a Session Factory level interceptor was provided, we use it

			if (Kernel.HasComponent("nhibernate.sessionfactory.interceptor"))
			{
				cfg.Interceptor = (IInterceptor) Kernel["nhibernate.sessionfactory.interceptor"];
			}
			// Registers the ISessionFactory as a component

			var model = new ComponentModel(id, typeof(ISessionFactory), typeof(Empty));
			model.LifestyleType = LifestyleType.Singleton;
			model.ExtendedProperties[Constants.SessionFactoryConfiguration] = cfg;
			model.CustomComponentActivator = typeof (SessionFactoryActivator);
			Kernel.AddCustomComponent(model);
			sessionFactoryResolver.RegisterAliasComponentIdMapping(alias, id);
		}
Esempio n. 10
0
        private void ConfigureFactories(IConfiguration config,
                                        ISessionFactoryResolver sessionFactoryResolver, bool firstFactory)
        {
            String id = config.Attributes["id"];

            if (id == null || String.Empty.Equals(id))
            {
                throw new ConfigurationErrorsException("You must provide a " +
                                                       "valid 'id' attribute for the 'factory' node. This id is used as key for " +
                                                       "the ISessionFactory component registered on the container");
            }

            String alias = config.Attributes["alias"];

            if (!firstFactory && (alias == null || alias.Length == 0))
            {
                throw new ConfigurationErrorsException("You must provide a " +
                                                       "valid 'alias' attribute for the 'factory' node. This id is used to obtain " +
                                                       "the ISession implementation from the SessionManager");
            }
            else if (alias == null || alias.Length == 0)
            {
                alias = Constants.DefaultAlias;
            }

            if (config.Attributes["isWeb"] == "true")
            {
                appRootPath = HttpContext.Current.Server.MapPath("~/");
            }
            else
            {
                appRootPath = Application.StartupPath;
            }

            NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();

            ApplyConfigurationSettings(cfg, config.Children["settings"]);
            RegisterAssemblies(cfg, config.Children["assemblies"]);
            RegisterResources(cfg, config.Children["resources"]);

            // Registers the Configuration object

            Kernel.AddComponentInstance(String.Format("{0}.cfg", id), cfg);

            // If a Session Factory level interceptor was provided, we use it

            if (Kernel.HasComponent("nhibernate.sessionfactory.interceptor"))
            {
                cfg.Interceptor = (IInterceptor)Kernel["nhibernate.sessionfactory.interceptor"];
            }

            // Registers the ISessionFactory as a component

            ISessionFactory sessionFactory = cfg.BuildSessionFactory();

            Kernel.AddComponentInstance(id, typeof(ISessionFactory), sessionFactory);

            // Registers the ISessionFactory within the ISessionFactoryResolver

            sessionFactoryResolver.RegisterAliasComponentIdMapping(alias, id);
        }
Esempio n. 11
0
		private void ConfigureFactories(IConfiguration config, 
			ISessionFactoryResolver sessionFactoryResolver, bool firstFactory)
		{
			String id = config.Attributes["id"];

			if (id == null || String.Empty.Equals(id))
			{
				String message = "You must provide a " + 
					"valid 'id' attribute for the 'factory' node. This id is used as key for " + 
					"the ISessionFactory component registered on the container";

				throw new ConfigurationErrorsException(message);
			}

			String alias = config.Attributes["alias"];

			if (!firstFactory && (alias == null || alias.Length == 0))
			{
				String message = "You must provide a " + 
					"valid 'alias' attribute for the 'factory' node. This id is used to obtain " + 
					"the ISession implementation from the SessionManager";

				throw new ConfigurationErrorsException(message);
			}
			else if (alias == null || alias.Length == 0)
			{
				alias = Constants.DefaultAlias;
			}

			Configuration cfg = new Configuration();

			ApplyConfigurationSettings(cfg, config.Children["settings"]);
			RegisterAssemblies(cfg, config.Children["assemblies"]);
			RegisterResources(cfg, config.Children["resources"]);

			// Registers the Configuration object

			Kernel.AddComponentInstance( String.Format("{0}.cfg", id), cfg );

			// If a Session Factory level interceptor was provided, we use it

			if (Kernel.HasComponent("nhibernate.sessionfactory.interceptor"))
			{
				cfg.Interceptor = (IInterceptor) Kernel["nhibernate.sessionfactory.interceptor"];
			}

			// Registers the ISessionFactory as a component

			ISessionFactory sessionFactory = cfg.BuildSessionFactory();

			Kernel.AddComponentInstance( id, typeof(ISessionFactory), sessionFactory );

			// Registers the ISessionFactory within the ISessionFactoryResolver

			sessionFactoryResolver.RegisterAliasComponentIdMapping(alias, id);
		}
Esempio n. 12
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="DefaultSessionManager" /> class.
 /// </summary>
 /// <param name="sessionStore">The session store.</param>
 /// <param name="kernel">The kernel.</param>
 /// <param name="factoryResolver">The factory resolver.</param>
 public DefaultSessionManager(ISessionStore sessionStore, IKernel kernel, ISessionFactoryResolver factoryResolver)
 {
     this._kernel          = kernel;
     this._sessionStore    = sessionStore;
     this._factoryResolver = factoryResolver;
 }
		public CurrentSessionContextImpl(ISessionFactoryResolver sessionFactoryResolver)
		{
			_sessionFactoryResolver = Verify.ArgumentNotNull(sessionFactoryResolver, "sessionFactoryResolver");
		}