• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Core.DependencyModel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: CanResolve

		/// <summary>
		///   Returns true if the resolver is able to satisfy the specified dependency.
		/// </summary>
		/// <param name = "context">Creation context, which is a resolver itself</param>
		/// <param name = "contextHandlerResolver">Parent resolver</param>
		/// <param name = "model">Model of the component that is requesting the dependency</param>
		/// <param name = "dependency">The dependency model</param>
		/// <returns>
		///   <c>true</c>
		///   if the dependency can be satisfied</returns>
		public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
		{
			// 1 - check for the dependency on CreationContext, if present
			if (CanResolveFromContext(context, contextHandlerResolver, model, dependency))
			{
				return true;
			}

			// 2 - check with the model's handler, if not the same as the parent resolver
			if (CanResolveFromHandler(context, contextHandlerResolver, model, dependency))
			{
				return true;
			}

			// 3 - check within parent resolver, if present
			if (CanResolveFromContextHandlerResolver(context, contextHandlerResolver, model, dependency))
			{
				return true;
			}

			// 4 - check within subresolvers
			if (CanResolveFromSubResolvers(context, contextHandlerResolver, model, dependency))
			{
				return true;
			}

			// 5 - normal flow, checking against the kernel
			return CanResolveFromKernel(context, model, dependency);
		}
开发者ID:jmuralimohanbabu,项目名称:Castle.Windsor,代码行数:39,代码来源:DefaultDependencyResolver.cs


示例17: IsValidFor

        public Boolean IsValidFor( DependencyModel model )
        {
            if ( model.DependencyKey == DependencyName ||
                 model.TargetType == TypeKey )
                return true;

            return false;
        }
开发者ID:aozora,项目名称:arashi,代码行数:8,代码来源:StrategyKey.cs


示例18: CanResolve

 public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver,
                        ComponentModel model,
                        DependencyModel dependency)
 {
     return dependency.TargetType != null &&
            dependency.TargetType.IsArray &&
            dependency.TargetType.GetElementType().IsInterface;
 }
开发者ID:somlea-george,项目名称:sutekishop,代码行数:8,代码来源:ArrayResolver.cs


示例19: Resolve

		public override object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver,
		                               ComponentModel model,
		                               DependencyModel dependency)
		{
			var items = base.Resolve(context, contextHandlerResolver, model, dependency);
			var listType = BuildListType(dependency);
			return listType.CreateInstance<object>(items);
		}
开发者ID:pmcg,项目名称:Castle.Windsor,代码行数:8,代码来源:ListResolver.cs


示例20: CanResolve

        public bool CanResolve(
			CreationContext context,
			ISubDependencyResolver parentResolver,
			ComponentModel model,
			DependencyModel dependency )
        {
            return dependency.DependencyType == DependencyType.Service;
        }
开发者ID:aozora,项目名称:arashi,代码行数:8,代码来源:AutoMockingDependencyResolver.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Configuration.MutableConfiguration类代码示例发布时间:2022-05-24
下一篇:
C# Core.ComponentModel类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap