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


C# Core.DependencyModel类代码示例

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


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

示例1: Resolve

        public object Resolve(
			 CreationContext context,
			 ISubDependencyResolver parentResolver,
			 ComponentModel model,
			 DependencyModel dependency)
        {
            MockingStrategy strategy = _relatedRepository.GetStrategyFor(dependency);

            if (strategy.Instance != null)
                return strategy.Instance;
            if (strategy.Mock == MockingStrategyType.Mock)
            {
                //if a dependencywas already registered in the main controller, go and use it
                var registration = this._relatedRepository.Kernel.GetHandler(dependency.TargetType);
                object resolvedDependencyObject;
                if (registration == null)
                {
                    resolvedDependencyObject = MockRepository.GenerateStub(dependency.TargetType);
                }
                else
                {
                    resolvedDependencyObject = _relatedRepository.Resolve(dependency.TargetType);
                }
                _relatedRepository.OnMockCreated(resolvedDependencyObject, dependency.DependencyKey);
                return resolvedDependencyObject;
            }
            if (strategy.Mock == MockingStrategyType.Resolve)
                return _relatedRepository.Resolve(dependency.TargetType);

            return null;
        }
开发者ID:alkampfergit,项目名称:ShuppanButsu,代码行数:31,代码来源:AutoMockingDependencyResolver.cs

示例2: 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

示例3: 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

示例4: Inspect

		public void Inspect(IHandler handler, DependencyModel[] missingDependencies, IKernel kernel)
		{
			if (handlersChecked.Add(handler) == false)
			{
				return;
			}
			Debug.Assert(missingDependencies.Length > 0, "missingDependencies.Length > 0");
			var uniqueOverrides = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			message.AppendLine();
			message.AppendFormat("'{0}' is waiting for the following dependencies:", handler.ComponentModel.Name);
			message.AppendLine();
			foreach (var dependency in missingDependencies)
			{
				if (dependency.ReferencedComponentName != null)
				{
					// NOTE: that's a workaround for us having dependency twice potentially, once from configuration and once from actual type scan
					if (uniqueOverrides.Add(dependency.ReferencedComponentName))
					{
						InspectServiceOverrideDependency(dependency, kernel);
					}
				}
				else if (dependency.IsPrimitiveTypeDependency)
				{
					//hardcoding string as it's a most common type that is not value type but you wouldn't want to kave that as a service.
					InspectParameterDependency(dependency);
				}
				else
				{
					InspectServiceDependency(handler, dependency, kernel);
				}
			}
		}
开发者ID:RookieX,项目名称:Windsor,代码行数:32,代码来源:DependencyInspector.cs

示例5: Resolve

 public object Resolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
     DependencyModel dependency)
 {
     if (dependency.TargetType == typeof (ISession))
         return SessionFactory.OpenSession();
     return SessionFactory.OpenStatelessSession();
 }
开发者ID:brumschlag,项目名称:rhino-tools,代码行数:7,代码来源:SessionResolver.cs

示例6: Resolve

			public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model,
			                      DependencyModel dependency)
			{
				return contextHandlerResolver.Resolve(context, contextHandlerResolver, model,
				                                      new DependencyModel(DependencyType.Service, typeof(IBookStore).FullName,
				                                                          typeof(IBookStore), false));
			}
开发者ID:ralescano,项目名称:castle,代码行数:7,代码来源:SubResolversShouldNotBeTrustedToBeCorrect.cs

示例7: TrackDependency

		private DependencyModelExtended TrackDependency(ComponentModel model, MemberInfo info, DependencyModel dependencyModel)
		{
			DependencyModelExtended trackingKey = new DependencyModelExtended(model, dependencyModel, info);

			if (dependencies.Contains(trackingKey))
			{
				StringBuilder sb = new StringBuilder("A cycle was detected when trying to resolve a dependency. ");

				sb.Append("The dependency graph that resulted in a cycle is:");

				foreach(DependencyModel key in dependencies)
				{
					DependencyModelExtended extendedInfo = key as DependencyModelExtended;

					if (extendedInfo != null)
					{
						sb.AppendFormat("\r\n - {0} for {1} in type {2}",
						                key, extendedInfo.Info, extendedInfo.Info.DeclaringType);
					}
					else
					{
						sb.AppendFormat("\r\n - {0}", key);
					}
				}

				sb.AppendFormat("\r\n + {0} for {1} in {2}\r\n",
				                dependencyModel, info, info.DeclaringType);

				throw new CircularDependencyException(sb.ToString());
			}

			dependencies.Add(trackingKey);

			return trackingKey;
		}
开发者ID:ralescano,项目名称:castle,代码行数:35,代码来源:DependencyTrackingScope.cs

示例8: CanResolve

        public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
                               DependencyModel dependency)
        {

            return Context.CurrentUser != null &&
                   dependency.TargetType == typeof (INotifications);
        }
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:7,代码来源:NotificationResolver.cs

示例9: Inspect

		public void Inspect(IHandler handler, DependencyModel[] missingDependencies, IKernel kernel)
		{
			if (handlersChecked.Add(handler) == false)
			{
				return;
			}
			Debug.Assert(missingDependencies.Length > 0, "missingDependencies.Length > 0");

			message.AppendLine();
			message.AppendFormat("'{0}' is waiting for the following dependencies:", handler.ComponentModel.Name);
			message.AppendLine();
			foreach (var dependency in missingDependencies)
			{
				switch (dependency.DependencyType)
				{
					case DependencyType.Service:
						InspectServiceDependency(handler, dependency, kernel);
						break;
					case DependencyType.ServiceOverride:
						InspectServiceOverrideDependency(dependency, kernel);
						break;
					case DependencyType.Parameter:
						InspectParameterDependency(dependency);
						break;
				}
			}
		}
开发者ID:thefringeninja,项目名称:Castle.Windsor,代码行数:27,代码来源:DependencyInspector.cs

示例10: 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

示例11: CanResolve

        public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
        {
			return dependency.TargetType != null &&
			       dependency.TargetType.IsArray &&
			       dependency.TargetType.GetElementType().IsInterface &&
				   !model.Parameters.Contains(dependency.DependencyKey);
        }
开发者ID:Slesa,项目名称:Playground,代码行数:7,代码来源:ArraySubDependencyResolver.cs

示例12: Resolve

 public object Resolve(CreationContext context, ISubDependencyResolver parentResolver,
     ComponentModel model,
     DependencyModel dependency)
 {
     Type t = dependency.TargetType.GetGenericArguments()[0];
     return kernel.ResolveAll(t, null);
 }
开发者ID:emmekappa,项目名称:horn_src,代码行数:7,代码来源:EnumerableResolver.cs

示例13: Resolve

		public object Resolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
							  DependencyModel dependency)
		{
			Type elementType = dependency.TargetType.GetElementType();
			Array all = kernel.ResolveAll(elementType, new Hashtable());
			return all;
		}
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:7,代码来源:ArrayOfComponentsResolver.cs

示例14: 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

示例15: CreateConstructorCandidate

		protected virtual ConstructorCandidate CreateConstructorCandidate(ConstructorInfo constructor)
		{
			ParameterInfo[] parameters = constructor.GetParameters();

			DependencyModel[] dependencies = new DependencyModel[parameters.Length];

			for(int i = 0; i < parameters.Length; i++)
			{
				ParameterInfo parameter = parameters[i];

				Type paramType = parameter.ParameterType;

				// This approach is somewhat problematic. We should use
				// another strategy to differentiate types and classify dependencies
				if (converter.IsSupportedAndPrimitiveType(paramType))
				{
					dependencies[i] = new DependencyModel(
						DependencyType.Parameter, parameter.Name, paramType, false);
				}
				else
				{
					dependencies[i] = new DependencyModel(
						DependencyType.Service, parameter.Name, paramType, false);
				}
			}

			return new ConstructorCandidate(constructor, dependencies);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:28,代码来源:ConstructorDependenciesModelInspector.cs


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