示例#1
0
		public void ProcessModel(IKernel kernel, ComponentModel model)
		{
			if (model.Configuration == null)
			{
				return;
			}

			var mixins = model.Configuration.Children["mixins"];
			if (mixins == null)
			{
				return;
			}

			var mixinReferences = new List<ComponentReference<object>>();
			foreach (var mixin in mixins.Children)
			{
				var value = mixin.Value;

				var mixinComponent = ReferenceExpressionUtil.ExtractComponentKey(value);
				if (mixinComponent == null)
				{
					throw new Exception(
						String.Format("The value for the mixin must be a reference to a component (Currently {0})", value));
				}

				mixinReferences.Add(new ComponentReference<object>("mixin-" + mixinComponent, mixinComponent));
			}
			if (mixinReferences.Count == 0)
			{
				return;
			}
			var options = model.ObtainProxyOptions();
			mixinReferences.ForEach(options.AddMixinReference);
		}
		public override object Create(IKernel kernel, object instance, ComponentModel model, 
									  CreationContext context, params object[] constructorArguments)
		{
			var channelHolder = instance as IWcfChannelHolder;

			if (channelHolder == null)
			{
				throw new ArgumentException(string.Format("Given instance is not an {0}", typeof(IWcfChannelHolder)), "instance");
			}

			if (channelHolder.RealProxy == null)
			{
				return channelHolder.Channel;
			}

			if (model.Services.Count() > 1)
			{
				throw new ArgumentException(string.Format(
					"Component {0}, which was designated as a WCF proxy exposes {1} services. The facility currently only supports single-service components.",
					model.Name, model.Services.Count()));
			}

			var isDuplex = IsDuplex(channelHolder.RealProxy);
			var proxyOptions = model.ObtainProxyOptions();
			var serviceContract = model.GetServiceContract();
			var generationOptions = CreateProxyGenerationOptions(serviceContract, proxyOptions, kernel, context);
			var additionalInterfaces = GetInterfaces(model.Services, proxyOptions, isDuplex);
			var interceptors = GetInterceptors(kernel, model, serviceContract, channelHolder, context);

			return generator.CreateInterfaceProxyWithTarget(typeof(IWcfChannelHolder),
				additionalInterfaces, channelHolder, generationOptions, interceptors);
		}
示例#3
0
		public void BuildComponentModel(IKernel kernel, ComponentModel model)
		{
			if (!mixIns.Any())
			{
				return;
			}
			var options = model.ObtainProxyOptions();
			foreach (var mixIn in mixIns)
			{
				options.AddMixinReference(mixIn);
			}
		}
		public void AddTypedFactoryEntry(FactoryEntry entry)
		{
			var model = new ComponentModel(new ComponentName(entry.Id, true), new[] { entry.FactoryInterface }, typeof(Empty),
			                               new Arguments().Insert("typed.fac.entry", entry))
			{ LifestyleType = LifestyleType.Singleton };

			model.Interceptors.Add(new InterceptorReference(typeof(FactoryInterceptor)));

			var proxyOptions = model.ObtainProxyOptions();
			proxyOptions.OmitTarget = true;

			((IKernelInternal)Kernel).AddCustomComponent(model);
		}
示例#5
0
		public override object Create(IProxyFactoryExtension customFactory, IKernel kernel, ComponentModel model, CreationContext context,
		                              params object[] constructorArguments)
		{
			var interceptors = ObtainInterceptors(kernel, model, context);
			var proxyOptions = model.ObtainProxyOptions();
			var proxyGenOptions = CreateProxyGenerationOptionsFrom(proxyOptions, kernel, context, model);

			CustomizeOptions(proxyGenOptions, kernel, model, constructorArguments);
			var builder = generator.ProxyBuilder;
			var proxy = customFactory.Generate(builder, proxyGenOptions, interceptors, model, context);

			CustomizeProxy(proxy, proxyGenOptions, kernel, model);
			ReleaseHook(proxyGenOptions, kernel);
			return proxy;
		}
		protected virtual void CollectFromConfiguration(ComponentModel model)
		{
			if (model.Configuration == null)
			{
				return;
			}

			var interceptors = model.Configuration.Children["interceptors"];
			if (interceptors == null)
			{
				return;
			}

			CollectInterceptors(model, interceptors);
			var options = model.ObtainProxyOptions();
			CollectSelector(interceptors, options);
			CollectHook(interceptors, options);
		}
示例#7
0
        public bool ShouldCreateProxy(ComponentModel model)
        {
            if (model.HasInterceptors)
            {
                return true;
            }

            var options = model.ObtainProxyOptions(false);
            if (options != null && options.RequiresProxy)
            {
                return true;
            }
            if (selectors != null && selectors.Any(s => s.HasInterceptors(model)))
            {
                return true;
            }

            return false;
        }
示例#8
0
		public override object Create(IKernel kernel, object instance, ComponentModel model, 
									  CreationContext context, params object[] constructorArguments)
		{
			var channelHolder = instance as IWcfChannelHolder;

			if (channelHolder == null)
			{
				throw new ArgumentException(string.Format("Given instance is not an {0}", typeof(IWcfChannelHolder)), "instance");
			}

			var isDuplex = IsDuplex(channelHolder.RealProxy);
			var proxyOptions = model.ObtainProxyOptions();
			var serviceContract = model.GetServiceContract();
			var remainingServices = model.Services.Except(new[] { serviceContract });
			var generationOptions = CreateProxyGenerationOptions(serviceContract, proxyOptions, kernel, context);
			generationOptions.AddMixinInstance(channelHolder);
			var additionalInterfaces = GetInterfaces(remainingServices, proxyOptions, isDuplex);
			var interceptors = GetInterceptors(kernel, model, serviceContract, channelHolder, context);

			return generator.CreateInterfaceProxyWithTargetInterface(serviceContract,
				additionalInterfaces, channelHolder.Channel, generationOptions, interceptors);
		}
		/// <summary>
		///   Applies the synchronization support to the model.
		/// </summary>
		/// <param name = "model">The model.</param>
		/// <param name = "kernel">The kernel.</param>
		private void ApplySynchronization(ComponentModel model, IKernel kernel)
		{
			var options = model.ObtainProxyOptions();

			model.Interceptors.Add(new InterceptorReference(typeof(SynchronizeInterceptor)));

			var metaInfo = metaStore.GetMetaFor(model.Implementation);

			if (metaInfo != null)
			{
				IInterceptorSelector userSelector = null;
				if (options.Selector != null)
				{
					userSelector = options.Selector.Resolve(kernel, CreationContext.CreateEmpty());
				}

				options.Selector = new InstanceReference<IInterceptorSelector>(new SynchronizeInterceptorSelector(metaInfo, userSelector));

				foreach (var reference in metaInfo.GetUniqueSynchContextReferences())
				{
					model.Dependencies.Add(new DependencyModel(reference.ComponentKey, reference.ServiceType, false));
				}
			}
		}
		public void BuildComponentModel(IKernel kernel, ComponentModel model)
		{
			var options = model.ObtainProxyOptions();
			options.Selector = selector;
		}
		public void BuildComponentModel(IKernel kernel, ComponentModel model)
		{
			var options = model.ObtainProxyOptions();
			options.AddAdditionalInterfaces(interfaces);
		}
		private void ConfigureProxyOptions(ComponentModel model)
		{
			if (controlProxyHook == null)
			{
				return;
			}
			var proxyOptions = model.ObtainProxyOptions();
			proxyOptions.Hook = controlProxyHook;
		}
示例#13
0
		/// <summary>
		///   Creates the proxy for the supplied component.
		/// </summary>
		/// <param name="kernel"> The kernel. </param>
		/// <param name="target"> The target. </param>
		/// <param name="model"> The model. </param>
		/// <param name="constructorArguments"> The constructor arguments. </param>
		/// <param name="context"> The creation context </param>
		/// <returns> The component proxy. </returns>
		public override object Create(IKernel kernel, object target, ComponentModel model, CreationContext context, params object[] constructorArguments)
		{
			object proxy;

			var interceptors = ObtainInterceptors(kernel, model, context);
			var proxyOptions = model.ObtainProxyOptions();
			var proxyGenOptions = CreateProxyGenerationOptionsFrom(proxyOptions, kernel, context, model);

			CustomizeOptions(proxyGenOptions, kernel, model, constructorArguments);

			var interfaces = proxyOptions.AdditionalInterfaces;
			if (model.HasClassServices == false)
			{
				var firstService = model.Services.First();
				var additionalInterfaces = model.Services.Skip(1).Concat(interfaces).ToArray();
				if (proxyOptions.OmitTarget)
				{
					proxy = generator.CreateInterfaceProxyWithoutTarget(firstService, additionalInterfaces, proxyGenOptions, interceptors);
				}
				else if (proxyOptions.AllowChangeTarget)
				{
					proxy = generator.CreateInterfaceProxyWithTargetInterface(firstService, additionalInterfaces, target, proxyGenOptions, interceptors);
				}
				else
				{
					proxy = generator.CreateInterfaceProxyWithTarget(firstService, additionalInterfaces, target, proxyGenOptions, interceptors);
				}
			}
			else
			{
				Type classToProxy;
				if (model.Implementation != null && model.Implementation != typeof(LateBoundComponent))
				{
					classToProxy = model.Implementation;
				}
				else
				{
					classToProxy = model.Services.First();
				}
				var additionalInterfaces = model.Services
					.SkipWhile(s => s.IsClass)
					.Concat(interfaces)
					.ToArray();
				proxy = generator.CreateClassProxy(classToProxy, additionalInterfaces, proxyGenOptions, constructorArguments, interceptors);
			}

			CustomizeProxy(proxy, proxyGenOptions, kernel, model);
			ReleaseHook(proxyGenOptions, kernel);
			return proxy;
		}
示例#14
0
		/// <summary>
		///   Determines if the component requires a target instance for proxying.
		/// </summary>
		/// <param name="kernel"> The kernel. </param>
		/// <param name="model"> The model. </param>
		/// <returns> true if an instance is required. </returns>
		public override bool RequiresTargetInstance(IKernel kernel, ComponentModel model)
		{
			var proxyOptions = model.ObtainProxyOptions();

			return model.HasClassServices == false &&
			       proxyOptions.OmitTarget == false;
		}
示例#15
0
		private static void ApplyProxyBehavior(ComponentProxyBehaviorAttribute behavior, ComponentModel model)
		{
			var options = model.ObtainProxyOptions();
#if !SILVERLIGHT
			if (behavior.UseMarshalByRefProxy)
			{
				EnsureComponentRegisteredWithInterface(model);
			}
			options.UseMarshalByRefAsBaseClass = behavior.UseMarshalByRefProxy;
#endif
			options.AddAdditionalInterfaces(behavior.AdditionalInterfaces);
			if(model.Implementation.IsInterface)
			{
				options.OmitTarget = true;
			}
		}
示例#16
0
		public void BuildComponentModel(IKernel kernel, ComponentModel model)
		{
			var options = model.ObtainProxyOptions();
			options.Hook = hook;
		}