Example #1
0
        public void Contribute(IKernel kernel, ComponentModel model)
        {
            var actorFlag = IsActorType(model) &&
                            HasActorAttributeSet(model, kernel.GetConversionManager());

            model.SetProperty(FacilityConstants.ActorKey, actorFlag);
            if (actorFlag)
            {
                var actorServiceType = GetActorServiceTypeAttribute(model, kernel.GetConversionManager()) ?? typeof(ActorService);
                model.SetProperty(FacilityConstants.ActorServiceTypeKey, actorServiceType);
            }
        }
		/// <summary>
		/// Reads the proxy behavior associated with the 
		/// component configuration/type and applies it to the model.
		/// </summary>
		/// <exception cref="System.Exception">
		/// If the conversion fails
		/// </exception>
		/// <param name="kernel"></param>
		/// <param name="model"></param>
		protected virtual void ReadProxyBehavior(IKernel kernel, ComponentModel model)
		{
			ComponentProxyBehaviorAttribute proxyBehaviorAtt = GetProxyBehaviorFromType(model.Implementation);

			if (proxyBehaviorAtt == null)
			{
				proxyBehaviorAtt = new ComponentProxyBehaviorAttribute();
			}

			string useSingleInterfaceProxyAttrib = model.Configuration != null ? model.Configuration.Attributes["useSingleInterfaceProxy"] : null;
			
#if !SILVERLIGHT
			string marshalByRefProxyAttrib = model.Configuration != null ? model.Configuration.Attributes["marshalByRefProxy"] : null;
#endif

			var converter = kernel.GetConversionManager();
			if (useSingleInterfaceProxyAttrib != null)
			{
#pragma warning disable 0618 //call to obsolete method
				proxyBehaviorAtt.UseSingleInterfaceProxy =
					converter.PerformConversion<bool?>(useSingleInterfaceProxyAttrib).GetValueOrDefault(false);
#pragma warning restore
			}
#if !SILVERLIGHT
			if (marshalByRefProxyAttrib != null)
			{
				proxyBehaviorAtt.UseMarshalByRefProxy =
					converter.PerformConversion<bool?>(marshalByRefProxyAttrib).GetValueOrDefault(false);
			}
#endif
			ApplyProxyBehavior(proxyBehaviorAtt, model);
		}
		private void EnsureConverterInitialized(IKernel kernel)
		{
			if(converter == null)
			{
				converter = kernel.GetConversionManager();
			}
		}
Example #4
0
        /// <summary>
        ///   Should obtain the contents from the resource,
        ///   interpret it and populate the <see cref="T:Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore" />
        ///   accordingly.
        /// </summary>
        /// <param name="resource"></param>
        /// <param name="store"></param>
        /// <param name="kernel"></param>
        public override void ProcessResource(IResource resource, IConfigurationStore store, IKernel kernel)
        {
            PropertiesJsonProcessor processor = new PropertiesJsonProcessor();

            processor.Process(resource);

            IConversionManager converter = kernel.GetConversionManager();

            // setup the properties resolver
            Resolver = new PropertyResolver(processor, converter);
            m_processResourceCalled = true;
        }
Example #5
0
        /// <summary>
        ///   Should obtain the contents from the resource,
        ///   interpret it and populate the <see cref="IConfigurationStore" />
        ///   accordingly.
        /// </summary>
        /// <param name="resource">Resource to process</param>
        /// <param name="store">Windsor configuration store</param>
        /// <param name="kernel">Windsor kernel</param>
        public override void ProcessResource(IResource resource, IConfigurationStore store, IKernel kernel)
        {
            var resourceSubSystem = kernel.GetSubSystem(SubSystemConstants.ResourceKey) as IResourceSubSystem;

            PropertiesXmlProcessor processor = new PropertiesXmlProcessor(EnvironmentName, resourceSubSystem);

            IConversionManager converter = kernel.GetConversionManager();

            processor.Process(resource);

            // setup the properties resolver
            m_resolver = new PropertyResolver(processor, converter);
            m_processResourceCalled = true;
        }
Example #6
0
		public override void ProcessResource(IResource source, IConfigurationStore store, IKernel kernel)
		{
			var resourceSubSystem = kernel.GetSubSystem(SubSystemConstants.ResourceKey) as IResourceSubSystem;
			var processor = new XmlProcessor.XmlProcessor(EnvironmentName, resourceSubSystem);

			try
			{
				var element = processor.Process(source);
				var converter = kernel.GetConversionManager();
				Deserialize(element, store, converter);
			}
			catch (XmlProcessorException e)
			{
				throw new ConfigurationProcessingException("Unable to process xml resource.", e);
			}
		}
Example #7
0
        public override void ProcessResource(IResource source, IConfigurationStore store, IKernel kernel)
        {
            var resourceSubSystem = kernel.GetSubSystem(SubSystemConstants.ResourceKey) as IResourceSubSystem;
            var processor         = new XmlProcessor.XmlProcessor(EnvironmentName, resourceSubSystem);

            try
            {
                var element   = processor.Process(source);
                var converter = kernel.GetConversionManager();
                Deserialize(element, store, converter);
            }
            catch (XmlProcessorException e)
            {
                throw new ConfigurationProcessingException("Unable to process xml resource.", e);
            }
        }
Example #8
0
        /// <summary>
        ///   Initializes the default contributors.
        /// </summary>
        protected virtual void InitializeContributors()
        {
            var conversionManager = kernel.GetConversionManager();

            AddContributor(new GenericInspector());
            AddContributor(new ConfigurationModelInspector());
            AddContributor(new ConfigurationParametersInspector());
            AddContributor(new LifestyleModelInspector(conversionManager));
            AddContributor(new ConstructorDependenciesModelInspector());
            AddContributor(new PropertiesDependenciesModelInspector(conversionManager));
            AddContributor(new LifecycleModelInspector());
            AddContributor(new InterceptorInspector());
            AddContributor(new MixinInspector());
            AddContributor(new ComponentActivatorInspector(conversionManager));
            AddContributor(new ComponentProxyInspector(conversionManager));
        }
		public virtual void ProcessModel(IKernel kernel, ComponentModel model)
		{
			if (converter == null)
			{
				converter = kernel.GetConversionManager();
			}

			var targetType = model.Implementation;

			var constructors = targetType.GetConstructors(BindingFlags.Public | BindingFlags.Instance);

			foreach(var constructor in constructors)
			{
				// We register each public constructor
				// and let the ComponentFactory select an 
				// eligible amongst the candidates later
				model.Constructors.Add(CreateConstructorCandidate(model, constructor));
			}
		}
        private static IReference <IProxyGenerationHook> ObtainProxyHook(IKernel kernel, IConfiguration config)
        {
            IProxyGenerationHook hook = null;

            if (config != null)
            {
                var hookAttrib = config.Attributes[Constants.ControlProxyHookAttrib];

                if (hookAttrib != null)
                {
                    var hookComponent = ReferenceExpressionUtil.ExtractComponentKey(hookAttrib);
                    if (hookComponent != null)
                    {
                        return(new ComponentReference <IProxyGenerationHook>("synchronize-proxy-generation-hook", hookComponent));
                    }

                    var converter = kernel.GetConversionManager();
                    var hookType  = converter.PerformConversion <Type>(hookAttrib);

                    if (hookType.Is <IProxyGenerationHook>() == false)
                    {
                        var message = String.Format("The specified controlProxyHook does " +
                                                    "not implement the interface {1}. Type {0}",
                                                    hookType.FullName, typeof(IProxyGenerationHook).Name);

                        throw new ConfigurationErrorsException(message);
                    }

                    hook = hookType.CreateInstance <IProxyGenerationHook>();
                }
            }

            if (hook == null)
            {
                hook = SynchronizeProxyHook.Instance;
            }

            return(new InstanceReference <IProxyGenerationHook>(hook));
        }
		public void ProcessModel(IKernel kernel, ComponentModel model)
		{
			if (model.Configuration == null) return;

			var interfaces = model.Configuration.Children["additionalInterfaces"];
			if (interfaces == null) return;

			if(converter == null)
			{
				converter = kernel.GetConversionManager();
			}
			var list = new List<Type>();
			foreach (var @interface in interfaces.Children
				.Where(c => c.Name.Equals("add", StringComparison.InvariantCultureIgnoreCase)))
			{
				var interfaceTypeName = @interface.Attributes["interface"];
				list.Add(converter.PerformConversion<Type>(interfaceTypeName));
			}

			var options = ProxyUtil.ObtainProxyOptions(model, true);
			options.AddAdditionalInterfaces(list.ToArray());
		}
		/// <summary>
		///   Reads the proxy behavior associated with the 
		///   component configuration/type and applies it to the model.
		/// </summary>
		/// <exception cref = "System.Exception">
		///   If the conversion fails
		/// </exception>
		/// <param name = "kernel"></param>
		/// <param name = "model"></param>
		protected virtual void ReadProxyBehavior(IKernel kernel, ComponentModel model)
		{
			var proxyBehaviorAtt = GetProxyBehaviorFromType(model.Implementation);

			if (proxyBehaviorAtt == null)
			{
				proxyBehaviorAtt = new ComponentProxyBehaviorAttribute();
			}

#if !SILVERLIGHT
			var marshalByRefProxyAttrib = model.Configuration != null ? model.Configuration.Attributes["marshalByRefProxy"] : null;
#endif

			var converter = kernel.GetConversionManager();
#if !SILVERLIGHT
			if (marshalByRefProxyAttrib != null)
			{
				proxyBehaviorAtt.UseMarshalByRefProxy =
					converter.PerformConversion<bool?>(marshalByRefProxyAttrib).GetValueOrDefault(false);
			}
#endif
			ApplyProxyBehavior(proxyBehaviorAtt, model);
		}
Example #13
0
        public void Contribute(IKernel kernel, ComponentModel model)
        {
            var serviceNameFlag = HasServiceTypeNameAttributeSet(model);

            var statefulFlag = IsStatefulType(model) && HasStatefulAttributeSet(model, kernel.GetConversionManager());

            model.SetProperty(FacilityConstants.StatefulServiceKey, serviceNameFlag && statefulFlag);

            if (serviceNameFlag && statefulFlag)
            {
                model.SetProperty(FacilityConstants.ServiceTypeNameKey, model.GetAttribute(FacilityConstants.ServiceTypeNameKey));
            }
        }
        /// <summary>
        ///   Should obtain the contents from the resource,
        ///   interpret it and populate the <see cref="IConfigurationStore" />
        ///   accordingly.
        /// </summary>
        /// <param name="resource">Resource to process</param>
        /// <param name="store">Windsor configuration store</param>
        /// <param name="kernel">Windsor kernel</param>
        public override void ProcessResource(IResource resource, IConfigurationStore store, IKernel kernel)
        {
            var resourceSubSystem = kernel.GetSubSystem(SubSystemConstants.ResourceKey) as IResourceSubSystem;

              PropertiesXmlProcessor processor = new PropertiesXmlProcessor(EnvironmentName, resourceSubSystem);

              IConversionManager converter = kernel.GetConversionManager();
              processor.Process(resource);

              // setup the properties resolver
              m_resolver = new PropertyResolver(processor, converter);
              m_processResourceCalled = true;
        }
        /// <summary>
        ///   Should obtain the contents from the resource,
        ///   interpret it and populate the <see cref="T:Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore" />
        ///   accordingly.
        /// </summary>
        /// <param name="resource"></param>
        /// <param name="store"></param>
        /// <param name="kernel"></param>
        public override void ProcessResource(IResource resource, IConfigurationStore store, IKernel kernel)
        {
            PropertiesJsonProcessor processor = new PropertiesJsonProcessor();
              processor.Process(resource);

              IConversionManager converter = kernel.GetConversionManager();

              // setup the properties resolver
              Resolver = new PropertyResolver(processor, converter);
              m_processResourceCalled = true;
        }
		/// <summary>
		///   Initializes this instance with the specified dependency delegate.
		/// </summary>
		/// <param name="kernel">kernel</param>
		/// <param name = "dependencyDelegate">The dependency delegate.</param>
		public void Initialize(IKernel kernel, DependencyDelegate dependencyDelegate)
		{
			this.kernel = kernel;
			converter = kernel.GetConversionManager();
			dependencyResolvingDelegate = dependencyDelegate;
		}
        public void Contribute(IKernel kernel, ComponentModel model)
        {
            var serviceNameFlag = HasServiceTypeNameAttributeSet(model);

            var statefulFlag = IsStatefulType(model) && HasStatefulAttributeSet(model, kernel.GetConversionManager());

            model.ExtendedProperties[FacilityConstants.StatefulServiceKey] = serviceNameFlag && statefulFlag;

            if (serviceNameFlag && statefulFlag)
            {
                model.ExtendedProperties[FacilityConstants.ServiceTypeNameKey] = model.Configuration.Attributes[FacilityConstants.ServiceTypeNameKey];
            }
        }
		private static IReference<IProxyGenerationHook> ObtainProxyHook(IKernel kernel, IConfiguration config)
		{
			IProxyGenerationHook hook = null;

			if (config != null)
			{
				var hookAttrib = config.Attributes[Constants.ControlProxyHookAttrib];

				if (hookAttrib != null)
				{
					if (ReferenceExpressionUtil.IsReference(hookAttrib))
					{
						var hookKey = ReferenceExpressionUtil.ExtractComponentKey(hookAttrib);
						return new ComponentReference<IProxyGenerationHook>(hookKey);
					}

					var converter = kernel.GetConversionManager();
					var hookType = converter.PerformConversion<Type>(hookAttrib);

					if (hookType.Is<IProxyGenerationHook>() == false)
					{
						var message = String.Format("The specified controlProxyHook does " +
						                            "not implement the interface {1}. Type {0}",
						                            hookType.FullName, typeof(IProxyGenerationHook).Name);

						throw new ConfigurationErrorsException(message);
					}

					hook = (IProxyGenerationHook)Activator.CreateInstance(hookType);
				}
			}

			if (hook == null)
			{
				hook = SynchronizeProxyHook.Instance;
			}

			return new InstanceReference<IProxyGenerationHook>(hook);
		}
        public void Contribute(IKernel kernel, ComponentModel model)
        {
            var actorFlag = IsActorType(model) && HasActorAttributeSet(model, kernel.GetConversionManager());

            model.ExtendedProperties[FacilityConstants.ActorKey] = actorFlag;
        }