当前位置: 首页>>代码示例>>C#>>正文


C# CreationContext类代码示例

本文整理汇总了C#中CreationContext的典型用法代码示例。如果您正苦于以下问题:C# CreationContext类的具体用法?C# CreationContext怎么用?C# CreationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CreationContext类属于命名空间,在下文中一共展示了CreationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Request

		public virtual object Request(CreationContext context)
		{
			object instance;

			using(rwlock.ForWriting())
			{

				if (available.Count != 0)
				{
					instance = available.Pop();

					if (instance == null)
					{
						throw new PoolException("Invalid instance on the pool stack");
					}
				}
				else
				{
					instance = componentActivator.Create(context);

					if (instance == null)
					{
						throw new PoolException("Activator didn't return a valid instance");
					}
				}

				inUse.Add(instance);
			}

			return instance;
		}
开发者ID:Huddle,项目名称:Castle.Windsor,代码行数:31,代码来源:DefaultPool.cs

示例2: Resolve

		public override object Resolve(CreationContext context)
		{
			HttpContext current = HttpContext.Current;

			if (current == null)
				throw new InvalidOperationException(
					"HttpContext.Current is null.  PerWebRequestLifestyle can only be used in ASP.Net");

			if (current.Items[PerRequestObjectID] == null)
			{
				if (!PerWebRequestLifestyleModule.Initialized)
				{
					string message = "Looks like you forgot to register the http module " +
					                 typeof(PerWebRequestLifestyleModule).FullName +
					                 "\r\nAdd '<add name=\"PerRequestLifestyle\" type=\"Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel\" />' " +
					                 "to the <httpModules> section on your web.config";

					throw new ConfigurationErrorsException(message);
				}

				object instance = base.Resolve(context);
				current.Items[PerRequestObjectID] = instance;
				PerWebRequestLifestyleModule.RegisterForEviction(this, instance);
			}

			return current.Items[PerRequestObjectID];
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:27,代码来源:PerWebRequestLifestyleManager.cs

示例3: ObtainInterceptors

		/// <summary>
		/// Obtains the interceptors associated with the component.
		/// </summary>
		/// <param name="kernel">The kernel instance</param>
		/// <param name="model">The component model</param>
		/// <param name="context">The creation context</param>
		/// <returns>interceptors array</returns>
		protected IInterceptor[] ObtainInterceptors(IKernel kernel, ComponentModel model, CreationContext context)
		{
			var interceptors = new List<IInterceptor>();
			foreach (IReference<IInterceptor> interceptorRef in GetInterceptorsFor(model))
			{
				try
				{
					var interceptor = interceptorRef.Resolve(kernel, context);
					SetOnBehalfAware(interceptor as IOnBehalfAware, model);
					interceptors.Add(interceptor);
				}
				catch (Exception e)
				{
					foreach (var interceptor in interceptors)
					{
						kernel.ReleaseComponent(interceptor);
					}

					if(e is InvalidCastException)
					{
						var message = String.Format(
						"An interceptor registered for {0} doesn't implement the {1} interface",
						model.Name, typeof(IInterceptor).Name);

						throw new DependencyResolverException(message);
					}
					throw;
				}
			}

			return interceptors.ToArray();
		}
开发者ID:pmcg,项目名称:Castle.Windsor,代码行数:39,代码来源:AbstractProxyFactory.cs

示例4: Resolve

 public object Resolve(CreationContext context,
     ISubDependencyResolver parentResolver,
     ComponentModel model,
     DependencyModel dependency)
 {
     return _kernel.ResolveAll(dependency.TargetType.GetElementType(), null);
 }
开发者ID:agross,项目名称:fizzbuzz,代码行数:7,代码来源:ArraySubDependencyResolver.cs

示例5: Resolve

		public override object Resolve(CreationContext context)
		{
			lock(slot)
			{
				var map = (Dictionary<IComponentActivator, object>)Thread.GetData(slot);

				if (map == null)
				{
					map = new Dictionary<IComponentActivator, object>();

					Thread.SetData( slot, map );
				}

				Object instance;

				if (!map.TryGetValue(ComponentActivator, out instance))
				{
					instance = base.Resolve(context);
					map.Add(ComponentActivator, instance);
					instances.Add(instance);
				}

				return instance;
			}
		}
开发者ID:Huddle,项目名称:Castle.Windsor,代码行数:25,代码来源:PerThreadLifestyleManager.cs

示例6: GetSubHandler

		protected IHandler GetSubHandler(CreationContext context, Type genericType)
		{
			lock(type2SubHandler)
			{
				IHandler handler;

				if (type2SubHandler.ContainsKey(genericType))
				{
					handler = type2SubHandler[genericType];
				}
				else
				{
					Type service = ComponentModel.Service.MakeGenericType(context.GenericArguments);

					ComponentModel newModel = Kernel.ComponentModelBuilder.BuildModel(
						ComponentModel.Name, service, genericType, null);

					newModel.ExtendedProperties[ComponentModel.SkipRegistration] = true;

					Kernel.AddCustomComponent(newModel);

					handler = Kernel.HandlerFactory.Create(newModel);

					type2SubHandler[genericType] = handler;
				}

				return handler;
			}
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:29,代码来源:DefaultGenericHandler.cs

示例7: CanResolve

		public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model,
		                       DependencyModel dependency)
		{
			return dependency.TargetType == typeof(IBookStore) && contextHandlerResolver.CanResolve(context, contextHandlerResolver, model,
			                                                                                        new DependencyModel(typeof(IBookStore).FullName,
			                                                                                                            typeof(IBookStore), false));
		}
开发者ID:dohansen,项目名称:Windsor,代码行数:7,代码来源:GoodDependencyResolver.cs

示例8: GetAzureServiceConfig

        private static IMicrosoftStorageConfig GetAzureServiceConfig(IKernel k, ComponentModel cm, CreationContext cc)
        {
            var serviceConfig = new DefaultAzureServiceConfigurationProvider(k.Resolve<IAppConfigSettings>()).GetConfigRaw();
            var webConfig = serviceConfig["Web"];

            return new DictionaryAdapterFactory().GetAdapter<IMicrosoftStorageConfig>(webConfig);
        }
开发者ID:ognyandim,项目名称:AzureStrongConfig,代码行数:7,代码来源:ContainerRegistrar.cs

示例9: Resolve

        public override object Resolve(CreationContext context)
        {
            var store = GetStore();

            var instance = base.Resolve(context);

            if (instance == null)
            {
                if (context.Handler.ComponentModel.ExtendedProperties[Constants.REG_IS_INSTANCE_KEY] != null)
                {
                    throw new DependencyResolutionException("Cannot find the instance in the context store.");
                }
            }
            else if (store[Model.Name] == null)
            {
                store[Model.Name] = instance;
                store.GetContextInstances().Add(new ContextStoreDependency(Model.Name, instance, this));
                _isRegisteredForCleanup = true;
            }

            if (!_isRegisteredForCleanup)
            {
                store.GetContextInstances().Add(new ContextStoreDependency(Model.Name, instance, this));
                _isRegisteredForCleanup = true;
            }
            return store[Model.Name];
        }
开发者ID:hibri,项目名称:openrasta-stable,代码行数:27,代码来源:ContextStoreLifetime.cs

示例10: Create

		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);
		}
开发者ID:AdamChang,项目名称:Castle.Facilities.Wcf-READONLY,代码行数:32,代码来源:WcfProxyFactory.cs

示例11: Resolve

		public override object Resolve(CreationContext context)
		{
			var current = HttpContext.Current;

			if (current == null)
				throw new InvalidOperationException(
					"HttpContext.Current is null. PerWebRequestLifestyle can only be used in ASP.Net");

			if (current.Items[PerRequestObjectID] == null)
			{
				if (!PerWebRequestLifestyleModule.Initialized)
				{
					var message =
						string.Format(
							"Looks like you forgot to register the http module {0}{1}Add '<add name=\"PerRequestLifestyle\" type=\"Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor\" />' to the <httpModules> section on your web.config",
							typeof(PerWebRequestLifestyleModule).FullName, Environment.NewLine);

					throw new Exception(message);
				}

				var instance = base.Resolve(context);
				current.Items[PerRequestObjectID] = instance;
				PerWebRequestLifestyleModule.RegisterForEviction(this, instance);
			}

			return current.Items[PerRequestObjectID];
		}
开发者ID:mdavis,项目名称:Castle.InversionOfControl,代码行数:27,代码来源:PerWebRequestLifestyleManager.cs

示例12: GetSubHandler

		protected IHandler GetSubHandler(CreationContext context, Type genericType)
		{
			lock (type2SubHandler)
			{
				IHandler handler;

				if (type2SubHandler.ContainsKey(genericType))
				{
					handler = type2SubHandler[genericType];
				}
				else
				{
					Type service = ComponentModel.Service.MakeGenericType(context.GenericArguments);

					ComponentModel newModel = Kernel.ComponentModelBuilder.BuildModel(
						ComponentModel.Name, service, genericType, null);

					newModel.ExtendedProperties[ComponentModel.SkipRegistration] = true;
					CloneParentProperties(newModel);

					// Create the handler and add to type2SubHandler before we add to the kernel.
					// Adding to the kernel could satisfy other dependencies and cause this method
					// to be called again which would result in extra instances being created.
					handler = Kernel.HandlerFactory.Create(newModel);
					type2SubHandler[genericType] = handler;

					Kernel.AddCustomComponent(newModel);
				}

				return handler;
			}
		}
开发者ID:ralescano,项目名称:castle,代码行数:32,代码来源:DefaultGenericHandler.cs

示例13: Resolve

 public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
 {
     string componentName = null;
     if (!_knownDependencies.ContainsKey(dependency))
         componentName = dependency.DependencyKey;
     return _kernel.Resolve(componentName, dependency.TargetType);
 }
开发者ID:gan123,项目名称:RightRecruit,代码行数:7,代码来源:ConventionBasedResolver.cs

示例14: CreateInstance

        protected override object CreateInstance(CreationContext context, ConstructorCandidate constructor, object[] arguments)
        {
            var commandHandler = base.CreateInstance(context, constructor, arguments);

            var result = chainBuilder.BuildChain(commandHandler);
            return result;
        }
开发者ID:gadjio,项目名称:Smi-Playground,代码行数:7,代码来源:CommandHandlerComponentActivator.cs

示例15: CanResolve

        /// <inheritdoc />
        public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, Castle.Core.ComponentModel model, DependencyModel dependency)
        {
            if (dependency.TargetType == null)
            {
                return false;
            }

            Type genericArgument = null;
            if ((dependency.TargetType.IsGenericType) && (dependency.TargetType.GetGenericTypeDefinition() == typeof(IEnumerable<>)))
            {
                genericArgument = dependency.TargetType.GetGenericArguments()[0];
            }
            else
            {
                dependency.TargetType.GetInterfaces().Any(implemented => (implemented.IsGenericType) && (implemented.GetGenericTypeDefinition() == typeof(IEnumerable<>)) &&
                    ((genericArgument = implemented.GetGenericArguments()[0]) != null));
            }

            if ((genericArgument == null) || (!_kernel.HasComponent(genericArgument)))
            {
                return false;
            }

            return true;
        }
开发者ID:alien-mcl,项目名称:URSA,代码行数:26,代码来源:AutoClosingCollectionResolver.cs


注:本文中的CreationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。