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


C# DependencyModel.Init方法代码示例

本文整理汇总了C#中Castle.Core.DependencyModel.Init方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyModel.Init方法的具体用法?C# DependencyModel.Init怎么用?C# DependencyModel.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Castle.Core.DependencyModel的用法示例。


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

示例1: AddDependency

		/// <summary>
		///   Invoked by
		///   <see cref = "InitDependencies" />
		///   in order to check if a dependency can be satisfied.
		///   If not, the handler is set to a 'waiting dependency' state.
		/// </summary>
		/// <remarks>
		///   This method registers the dependencies within the correct collection 
		///   or dictionary and changes the handler state to
		///   <see cref = "HandlerState.WaitingDependency" />
		/// </remarks>
		/// <param name = "dependency"></param>
		protected void AddDependency(DependencyModel dependency)
		{
			dependency.Init(model.ParametersInternal);
			if (AddOptionalDependency(dependency))
			{
				return;
			}
			if (AddResolvableDependency(dependency))
			{
				return;
			}
			AddMissingDependency(dependency);
		}
开发者ID:hjlfmy,项目名称:Castle.Windsor-READONLY,代码行数:25,代码来源:AbstractHandler.cs

示例2: Create

		private object Create(object factoryInstance, string factoryId, MethodInfo instanceCreateMethod, string factoryCreate, CreationContext context)
		{
			object instance;
			var methodArgs = new List<object>();
			try
			{
				var parameters = instanceCreateMethod.GetParameters();

				foreach (var parameter in parameters)
				{
					var paramType = parameter.ParameterType;

					if (paramType == typeof(IKernel))
					{
						methodArgs.Add(Kernel);
						continue;
					}
					else if (paramType == typeof(CreationContext))
					{
						methodArgs.Add(context);
						continue;
					}

					var dependency = new DependencyModel(parameter.Name, paramType, false);
					dependency.Init(Model.HasParameters ? Model.Parameters : null);
					if (!Kernel.Resolver.CanResolve(context, null, Model, dependency))
					{
						var message = String.Format(
							"Factory Method {0}.{1} requires an argument '{2}' that could not be resolved",
							instanceCreateMethod.DeclaringType.FullName, instanceCreateMethod.Name, parameter.Name);
						throw new FacilityException(message);
					}

					var arg = Kernel.Resolver.Resolve(context, null, Model, dependency);

					methodArgs.Add(arg);
				}

				instance = instanceCreateMethod.Invoke(factoryInstance, methodArgs.ToArray());
			}
			catch (Exception ex)
			{
				var message = String.Format("You have specified a factory " +
				                            "('{2}' - method to be called: {3}) " +
				                            "for the component '{0}' {1} that failed during invoke.",
				                            Model.Name, Model.Implementation.FullName, factoryId, factoryCreate);

				throw new FacilityException(message, ex);
			}

			if (Model.HasInterceptors)
			{
				try
				{
					instance = Kernel.ProxyFactory.Create(Kernel, instance, Model, context, methodArgs.ToArray());
				}
				catch (Exception ex)
				{
					throw new ComponentActivatorException("FactoryActivator: could not proxy " +
					                                      instance.GetType().FullName, ex);
				}
			}

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


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