public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { return dependency.TargetType != null && dependency.TargetType.IsArray && kernel.HasComponent(dependency.TargetType.GetElementType()); }
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { var targetType = dependency.TargetItemType; return targetType != null && targetType.IsArray && (allowEmptyArray || kernel.HasComponent(targetType.GetElementType())); }
public bool CanResolve( CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { return(ConfigurationManager.AppSettings.AllKeys .Contains(dependency.DependencyKey) && TypeDescriptor .GetConverter(dependency.TargetType) .CanConvertFrom(typeof(string))); }
private bool SettingExist(DependencyModel dependency) { try { var settingValue = _applicationSettingsBase[dependency.DependencyKey]; } catch (SettingsPropertyNotFoundException) { return(false); } return(true); }
/// <summary> /// Should return an instance of a service or property values as /// specified by the dependency model instance. /// It is also the responsibility of <see cref="T:Castle.MicroKernel.IDependencyResolver"/> /// to throw an exception in the case a non-optional dependency /// could not be resolved. /// </summary> /// <param name="context"> /// Creation context, which is a resolver itself. /// </param> /// <param name="contextHandlerResolver"> /// Parent resolver - normally the IHandler implementation. /// </param> /// <param name="model"> /// Model of the component that is requesting the dependency. /// </param> /// <param name="dependency"> /// The dependency model. /// </param> /// <returns> /// The dependency resolved value or null. /// </returns> public object Resolve( CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { var appSettingsKey = dependency.DependencyKey; var format = (PasswordFormat)Enum.Parse(typeof(PasswordFormat), ConfigurationManager.AppSettings[appSettingsKey]); return(format); }
/// <summary> /// Should return an instance of a service or property values as /// specified by the dependency model instance. /// It is also the responsibility of <see cref="T:Castle.MicroKernel.IDependencyResolver" /> /// to throw an exception in the case a non-optional dependency /// could not be resolved. /// </summary> /// <param name="context"> Creation context, which is a resolver itself </param> /// <param name="contextHandlerResolver"> Parent resolver - normally the IHandler implementation </param> /// <param name="model"> Model of the component that is requesting the dependency </param> /// <param name="dependency"> The dependency model </param> /// <returns> The dependency resolved value or null </returns> public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { if (this.CanResolve(context, contextHandlerResolver, model, dependency)) { if (dependency.TargetType == typeof(ILog)) { return LogManager.GetLogger(model.Implementation); } } return null; }
public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model, DependencyModel dependency) { bool result = dependency.TargetType != null && dependency.TargetType.GetGenericArguments().Length != 0 && typeof(IEnumerable <>) .MakeGenericType(dependency.TargetType.GetGenericArguments()[0]) .IsAssignableFrom(dependency.TargetType); return(result); }
public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model, DependencyModel dependency) { if (dependency.TargetItemType != typeof(Endpoint)) { return(false); } var endpointName = getEndpointName(model, dependency); return(this.Contains(endpointName)); }
private object Create(object factoryInstance, string factoryId, MethodInfo instanceCreateMethod, string factoryCreate) { ITypeConverter converter = (ITypeConverter)Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey); try { ParameterInfo[] parameters = instanceCreateMethod.GetParameters(); ArrayList methodArgs = new ArrayList(); foreach (ParameterInfo parameter in parameters) { Type paramType = parameter.ParameterType; DependencyModel depModel = null; if (converter.CanHandleType(paramType)) { depModel = new DependencyModel( DependencyType.Parameter, parameter.Name, paramType, false); } else { depModel = new DependencyModel( DependencyType.Service, parameter.Name, paramType, false); } if (!Kernel.Resolver.CanResolve(Model, depModel)) { String 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); } object arg = Kernel.Resolver.Resolve(Model, depModel); methodArgs.Add(arg); } return(instanceCreateMethod.Invoke(factoryInstance, methodArgs.ToArray())); } catch (Exception ex) { String 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); } }
private IHandler GetDependencyHandler(DependencyModel dependency) { if (dependency.ReferencedComponentName != null) { return(Kernel.GetHandler(dependency.ReferencedComponentName)); } if (dependency.TargetItemType != null) { return(Kernel.GetHandler(dependency.TargetItemType)); } return(null); }
public bool CanResolve( [NotNull] CreationContext context, [NotNull] ISubDependencyResolver contextHandlerResolver, [NotNull] ComponentModel model, [NotNull] DependencyModel dependency) { const string ControllerContext = "controllerContext"; return((dependency.TargetType == typeof(IRequestContext)) && context.AdditionalArguments.Contains(ControllerContext) && context.AdditionalArguments[ControllerContext] is ControllerContext); }
public virtual object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { var value = childResolver.Resolve(context, null, model, dependency); if (value == null) { value = parentHandler.Resolve(context, contextHandlerResolver, model, dependency); } return(value); }
public virtual object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { Debug.Assert(CanResolve(context, contextHandlerResolver, model, dependency), "CanResolve(context, contextHandlerResolver, model, dependency)"); object result = null; if (dependency.DependencyKey != null) { result = Resolve(dependency, additionalArguments[dependency.DependencyKey]); } return(result ?? Resolve(dependency, additionalArguments[dependency.TargetType])); }
public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { var fullName = model.ComponentName.Name.Split('.'); var name = fullName [fullName.Length - 1]; name = name.Substring(0, name.IndexOf(TRANSFORMER_SUFFIX)); var conf = m_cfgSource.Configs.Cast <IConfig> ().FirstOrDefault( c => c.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); return(conf ?? new IniConfig(name, m_cfgSource)); }
public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model, DependencyModel dependency) { if (dependency.TargetItemType != typeof(Endpoint)) { return(false); } var endpointName = getEndpointName(model, dependency); var canResolve = m_Endpoints.Any(p => p.Key.ToLower() == endpointName.ToLower()); return(canResolve); }
public void Visible_TrueWhenNotSpecified() { var dependencyModel = new DependencyModel( providerType: "someProvider", path: "somePath", originalItemSpec: "someItemSpec", flags: ProjectTreeFlags.Empty, resolved: true, isImplicit: false, properties: null); Assert.True(dependencyModel.Visible); }
public void Visible_False() { var dependencyModel = new DependencyModel( providerType: "someProvider", path: "somePath", originalItemSpec: "someItemSpec", flags: ProjectTreeFlags.Empty, resolved: true, isImplicit: false, properties: ImmutableDictionary <string, string> .Empty.Add("Visible", "false")); Assert.False(dependencyModel.Visible); }
/// <summary> /// Invoked by /// <see cref = "EnsureDependenciesCanBeSatisfied" /> /// 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); }
public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model, DependencyModel dependency) { if (dependency.TargetType.IsArray == false) { return(false); } Type elementType = dependency.TargetType.GetElementType(); return(kernel.HasComponent(elementType)); }
private void InspectServiceDependency(IHandler inspectingHandler, DependencyModel dependency, IKernel kernel) { var type = dependency.TargetItemType; var handler = kernel.GetHandler(type); if (handler == null) { message.AppendFormat("- Service '{0}' which was not registered.", type.FullName ?? type.Name); message.AppendLine(); } else if (handler == inspectingHandler) { var alternatives = kernel.GetHandlers(type); message.AppendFormat("- Service '{0}' which points back to the component itself.", type.FullName ?? type.Name); message.AppendLine(); message.Append("A dependency cannot be satisfied by the component itself, did you forget to "); if (alternatives.Length == 1) { message.AppendLine("register other components for this service?"); } else { message.AppendLine("make this a service override and point explicitly to a different component exposing this service?"); message.AppendLine(); message.Append("The following components also expose the service, but none of them can be resolved:"); foreach (var maybeDecoratedHandler in alternatives.Where(maybeDecoratedHandler => maybeDecoratedHandler != inspectingHandler)) { var info = maybeDecoratedHandler as IExposeDependencyInfo; if (info != null) { info.ObtainDependencyDetails(this); } else { message.AppendLine(); message.AppendFormat("'{0}' is registered and is matching the required service, but cannot be resolved.", maybeDecoratedHandler.ComponentModel.Name); } } } } else { message.AppendFormat("- Service '{0}' which was registered but is also waiting for dependencies.", handler.ComponentModel.Name); var info = handler as IExposeDependencyInfo; if (info != null) { info.ObtainDependencyDetails(this); } } }
public void Constructor_WhenOptionalValuesNotProvided_ShouldSetDefaults() { var model = new DependencyModel( providerType: "somProvider", path: "somePath", originalItemSpec: null, flags: ProjectTreeFlags.Empty, resolved: false, isImplicit: false, properties: null); Assert.Equal("somePath", model.OriginalItemSpec); Assert.Equal(ImmutableDictionary <string, string> .Empty, model.Properties); }
public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { var targetType = dependency.TargetType; var elementType = targetType.GetGenericArguments()[0]; var items = kernel.ResolveAll(elementType, null); var listType = typeof(List<>).MakeGenericType(elementType); var list = Activator.CreateInstance(listType, items); return list; }
private bool CanResolve(DependencyModel dependency, object inlineArgument) { var type = dependency.TargetItemType; if (type == null) { return(false); } if (inlineArgument == null) { return(type.IsNullable()); } return(type.IsInstanceOfType(inlineArgument) || CanConvertParameter(type)); }
public object Resolve( CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } return(provider .GetService <ILoggerFactory>() .CreateLogger(model.Name)); }
public override object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { var items = base.Resolve(context, contextHandlerResolver, model, dependency); // Services in container are registered in backward order (using .IsDefault() - see WindsorRegistrationHelper.RegisterServiceDescriptor). // However we need to return them in original order when returning collection so let's reverse them here. // Following check is probably unnecessary but let's be defensive and don't expect that it's always array what we get. if (items is Array) { Array.Reverse((Array)items); } return(items); }
private bool HasComponentInValidState(string key, DependencyModel dependency, CreationContext context) { IHandler handler; if (context != null && context.IsResolving) { handler = kernel.LoadHandlerByName(key, dependency.TargetItemType, context.AdditionalArguments); } else { handler = kernel.GetHandler(key); } return(IsHandlerInValidState(handler) && handler.IsBeingResolvedInContext(context) == false); }
public static GeneratedEdges For(ServiceModel[] services) { var edges = new List <DependencyModel>(); var createdServices = new List <ServiceModel>(); foreach (var service in services) { if (service.Dependencies == null) { continue; } foreach (var dependency in service.Dependencies) { var match = services.SingleOrDefault(s => s.Name == dependency.Name) ?? createdServices.SingleOrDefault(s => s.Name == dependency.Name); if (match == null) { match = new ServiceModel { Id = services.Length + createdServices.Count + 1, Name = dependency.Name, Environment = service.Environment, Color = dependency.IsHealthy ? "#00ff00" : "#ff0000", IsExternal = true, Dependencies = new DependencyStatus[0], IsHealthy = dependency.IsHealthy }; createdServices.Add(match); } var edge = new DependencyModel { From = service.Id, To = match.Id, Color = dependency.IsHealthy ? "#00ff00" : "#ff0000" }; edges.Add(edge); } } return(new GeneratedEdges { Edges = edges, CreatedServices = createdServices }); }
private static string getEndpointName(ComponentModel model, DependencyModel dependency) { var endpointName = dependency.DependencyKey; if (model.ExtendedProperties.Contains("endpointNames")) { var endpointNames = (IDictionary <string, string>)model.ExtendedProperties["endpointNames"]; if (endpointNames.ContainsKey(dependency.DependencyKey)) { endpointName = endpointNames[dependency.DependencyKey]; } } return(endpointName); }
public ComponentReference(string dependencyName, string componentKey) { if (dependencyName == null) { throw new ArgumentNullException("dependencyName"); } if (componentKey == null) { throw new ArgumentNullException("componentKey"); } serviceOverrideComponentKey = componentKey; dependency = new DependencyModel(dependencyName, typeof(T), false); }
public object Resolve( CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { var host = ConfigurationManager.AppSettings["MessageQueueHostServerName"]; if (null == host) { throw new InvalidProgramException("MessageQueueHostServerName missing from configuration store."); } return(ConfigurationManager.AppSettings["MessageQueueHostServerName"]); }
public virtual bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { if (dependency.TargetItemType == null) { return(false); } Type itemType = GetItemType(dependency.TargetItemType); if (itemType != null && !HasParameter(dependency)) { return(CanSatisfy(itemType)); } return(false); }
public ComponentReference(string dependencyName, string componentName) { if (dependencyName == null) { throw new ArgumentNullException("dependencyName"); } if (componentName == null) { throw new ArgumentNullException("componentName"); } value = componentName; dependency = new DependencyModel(dependencyName, typeof(T), false); }
public object Resolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model, DependencyModel dependency) { if (dependency.TargetItemType == typeof(ConnectionString)) { return(m_ConnectionStrings.First(p => p.Key.ToLower() == dependency.DependencyKey.ToLower()).Value); } if (dependency.TargetItemType == typeof(IDictionary <string, ConnectionString>)) { return(m_ConnectionStrings); } return(null); }
public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model, DependencyModel dependency) { if (dependency.TargetItemType == typeof(ConnectionString)) { return(m_ConnectionStrings.Any(p => p.Key.ToLower() == dependency.DependencyKey.ToLower())); } if (dependency.TargetItemType == typeof(IDictionary <string, ConnectionString>)) { return(m_ConnectionStrings.Any()); } return(false); }
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { var targetType = dependency.TargetType; if (targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(IList<>)) { var elementType = targetType.GetGenericArguments()[0]; return kernel.HasComponent(elementType); } return false; }
public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { if (this.CanResolve(context, contextHandlerResolver, model, dependency)) { if (dependency.TargetType.IsArray) { Type resolveType = dependency.TargetType.GetElementType(); return this.kernel.ResolveAll(resolveType); } if (dependency.TargetType.IsGenericType) { return this.kernel.ResolveAll(dependency.TargetType.GetGenericArguments()[0]); } } return null; }
/// <summary> /// Associates the transaction interceptor with the ComponentModel. /// </summary> /// <param name="model">The model.</param> /// <param name="store">The meta information store.</param> private static void AddTransactionInterceptorIfIsTransactional(ComponentModel model, TransactionMetaInfoStore store) { TransactionMetaInfo meta = store.GetMetaFor(model.Implementation); if (meta == null) { return; } var dpm = new DependencyModel(DependencyType.Service, typeof(TransactionInterceptor).FullName, typeof(TransactionInterceptor), false); model.Dependencies.Add(dpm); model.Interceptors.AddFirst(new InterceptorReference(typeof(TransactionInterceptor))); }
private object Resolve(DependencyModel dependency, object inlineArgument) { var targetType = dependency.TargetItemType; if (inlineArgument != null) { if (targetType.IsInstanceOfType(inlineArgument)) { return inlineArgument; } if (CanConvertParameter(targetType)) { return converter.PerformConversion(inlineArgument.ToString(), targetType); } } return null; }
private bool CanResolveByType(DependencyModel dependency) { var type = dependency.TargetItemType; if (type == null) { return false; } Debug.Assert(additionalArguments != null, "additionalArguments != null"); return CanResolve(dependency, additionalArguments[type]); }
/// <summary> /// Returns true if the resolver is able to satisfy this dependency. /// </summary> /// <param name="context"> Creation context, which is a resolver itself </param> /// <param name="contextHandlerResolver"> Parent resolver - normally the IHandler implementation </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) { return dependency.TargetType == typeof(ILog); }
private bool CanResolve(DependencyModel dependency, object inlineArgument) { var type = dependency.TargetItemType; if (inlineArgument == null || type == null) { return false; } return type.IsInstanceOfType(inlineArgument) || CanConvertParameter(type); }
private bool CanResolveByKey(DependencyModel dependency) { if (dependency.DependencyKey == null) { return false; } Debug.Assert(additionalArguments != null, "additionalArguments != null"); return CanResolve(dependency, additionalArguments[dependency.DependencyKey]); }
protected virtual void RaiseDependencyResolving(ComponentModel client, DependencyModel model, Object dependency) { DependencyDelegate eventDelegate = (DependencyDelegate) events[DependencyResolvingEvent]; if (eventDelegate != null) eventDelegate(client, model, dependency); }
public virtual object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { Debug.Assert(CanResolve(context, contextHandlerResolver, model, dependency), "CanResolve(context, contextHandlerResolver, model, dependency)"); object result = null; if (dependency.DependencyKey != null) { result = Resolve(dependency, additionalArguments[dependency.DependencyKey]); } return result ?? Resolve(dependency, additionalArguments[dependency.TargetType]); }
public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { return kernel.ResolveAll(dependency.TargetType.GetElementType(), null); }
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { return Result != null; }
public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { return Result.Value; }
public virtual bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { return HasAdditionalArguments && (CanResolveByKey(dependency) || CanResolveByType(dependency)); }
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) { return typeof(IEnumerable).IsAssignableFrom(dependency.TargetType) && dependency.TargetType != typeof(string); }