public ValidationResult InjectionPossible(SPI.Model.AbstractInjectableModel model) { var targetType = model.TargetType.GetGenericDefinitionIfContainsGenericParameters(); return(new ValidationResult( model.CompositeModel.GetAllCompositeTypes().Any(c => targetType.IsAssignableFrom_IgnoreGenericArgumentsForGenericTypes(c)), "Injection target must be composite type" )); }
public ValidationResult InjectionPossible(SPI.Model.AbstractInjectableModel model) { var targetType = model.TargetType; if (targetType.ContainsGenericParameters() && targetType.IsGenericType()) { targetType = targetType.GetGenericTypeDefinition(); } return(new ValidationResult( model.CompositeModel.ApplicationModel.GenericFragmentBaseType.IsAssignableFrom(targetType) || model.CompositeModel.GetAllCompositeTypes().Any(tt => targetType.IsAssignableFrom_IgnoreGenericArgumentsForGenericTypes(tt)), "Concern must be either generic or a sub-type of composite type." )); }
public InjectionTime GetInjectionTime(SPI.Model.AbstractInjectableModel model) { InjectionFunctionality func; var scope = model.InjectionScope; if (scope != null && this._functionalities.TryGetValue(scope.GetType(), out func)) { return(func.GetInjectionTime(model)); } else { return(InjectionTime.ON_CREATION); } }
public ValidationResult InjectionPossible(SPI.Model.AbstractInjectableModel model) { var targetType = model.TargetType; return(new ValidationResult( targetType.IsAssignableFrom(typeof(StructureServiceProviderSPI)) || targetType.IsAssignableFrom(typeof(ApplicationSPI)) || targetType.IsAssignableFrom(typeof(UsesProviderQuery)) || targetType.IsAssignableFrom(typeof(CollectionsFactory)) || targetType.IsAssignableFrom(typeof(CompositeModel)) || (model.CompositeModel is ServiceCompositeModel && targetType.IsAssignableFrom(typeof(ServiceCompositeModel))) || targetType.IsAssignableFrom(typeof(CompositeInstance)) || this.ValidateNonStandardInjection(model.CompositeModel, model, model.InjectionScope, targetType), "Target type must be one of the fixed structure types" )); }
public ValidationResult InjectionPossible(SPI.Model.AbstractInjectableModel model) { var targetType = model.TargetType; Boolean possible = typeof(CompositeState).IsAssignableFrom(targetType); ValidationResult result; if (possible) { result = new ValidationResult(typeof(CompositeState).IsAssignableFrom(targetType), null); } else { var attribute = model.InjectionScope as StateAttribute; if (attribute != null) { var suitableModels = this.FindSuitable <EventInfo, EventModel>( model.CompositeModel, model, attribute.ElementName, attribute.DeclaringType, method => method.EventModel, GetActualTargetType <CompositeEvent>(targetType), eventInfo => eventInfo.EventHandlerType ).ToArray(); var suitablePModels = this.FindSuitable <PropertyInfo, PropertyModel>( model.CompositeModel, model, attribute.ElementName, attribute.DeclaringType, method => method.PropertyModel, GetActualTargetType <CompositeProperty>(targetType), pInfo => pInfo.PropertyType ).ToArray(); Int32 totalLength = suitableModels.Length + suitablePModels.Length; result = new ValidationResult((model.IsOptional && totalLength <= 1) || (!model.IsOptional && totalLength == 1), totalLength == 0 ? "No suitable events nor properties found." : ("Too much suitable events and/or properties: " + String.Join(", ", (Object[])suitableModels) + String.Join(", ", (Object[])suitablePModels) + ".")); } else { result = new ValidationResult(false, "Injection scope of " + model + " was not of type " + typeof(StateAttribute)); } } return(result); }
public ValidationResult InjectionPossible(SPI.Model.AbstractInjectableModel model) { var targetType = model.TargetType; var scope = model.InjectionScope; ValidationResult result; InjectionFunctionality func; if (scope != null && this._functionalities.TryGetValue(scope.GetType(), out func)) { result = func.InjectionPossible(model); } else { result = new ValidationResult(false, scope == null ? "Injection scope was null" : ("No injection functionality found for injection scope " + scope.GetType())); } return(result); }
public ValidationResult InjectionPossible(SPI.Model.AbstractInjectableModel model) { var models = this.FindSuitableModels(model.CompositeModel, model, model.InjectionScope, model.TargetType, GetActualServiceType(model.TargetType).GetGenericDefinitionIfContainsGenericParameters()); ValidationResult retVal = null; foreach (var tuple in GetQualifierTypes(model)) { var qType = tuple.Item2.QualifierType; if (qType == null) { retVal = new ValidationResult(false, "Service qualifier callback type was null."); } else if (!typeof(ServiceQualifier).IsAssignableFrom(qType)) { retVal = new ValidationResult(false, "Qualifier type " + qType + " must implement " + typeof(ServiceQualifier) + "."); } else if (qType.ContainsGenericParameters()) { retVal = new ValidationResult(false, "Qualifier type " + qType + " must not contain open generic parameters."); } else if (!qType.GetAllInstanceConstructors().Any(ctor => ctor.IsPublic && ctor.GetParameters().Length == 0)) { retVal = new ValidationResult(false, "Qualifier type " + qType + "must contain parameterless constructor."); } if (retVal != null) { break; } var qInstance = (ServiceQualifier)tuple.Item2.QualifierType.LoadConstructorOrThrow(0).Invoke(null); models = models.Where(sModel => qInstance.Qualifies(sModel, tuple.Item1)); } return(retVal ?? new ValidationResult(models.Any(), "No suitable services found.")); // retVal ?? this.IsInjectionPossible( model.CompositeModel, model, model.InjectionScope, model.TargetType, TypeUtils.TypeUtil.GenericDefinitionIfContainsGenericParams( GetActualServiceType( model.TargetType ) ) ); }
protected virtual Boolean ValidateNonStandardInjection(SPI.Model.CompositeModel compositeModel, SPI.Model.AbstractInjectableModel model, Attribute scope, Type targetType) { return(false); }
protected override IEnumerable <ServiceCompositeModel> FindSuitableModels(SPI.Model.CompositeModel compositeModel, SPI.Model.AbstractInjectableModel model, Attribute scope, Type targetType, Type serviceType) { return(LayeredApplicationModelUtils.SearchVisibleModels( sModel => sModel.ModelType.Equals(CompositeModelType.SERVICE) && sModel.PublicTypes.Any(pType => serviceType.IsAssignableFrom_IgnoreGenericArgumentsForGenericTypes(pType)), (moduleModel, cModel) => cModel, ((LayeredApplicationModel)compositeModel.ApplicationModel).FindModuleModel(compositeModel) ).Cast <ServiceCompositeModel>()); //var matchingModel = LayeredApplicationModelUtils.FindFirstVisibleCompositeModel( ( (LayeredApplicationModel) compositeModel.ApplicationModel ).FindModuleModel( compositeModel ), CompositeModelType.SERVICE, serviceType ); //return new ValidationResult( matchingModel != null, "The service of type " + serviceType + " is either not present or not visible." ); }
public InjectionTime GetInjectionTime(SPI.Model.AbstractInjectableModel model) { return(InjectionTime.ON_CREATION); }
public ValidationResult InjectionPossible(SPI.Model.AbstractInjectableModel model) { // TODO check that no other same parameter or field is of same type and name. return(new ValidationResult(true, null)); }
protected abstract IEnumerable <ServiceCompositeModel> FindSuitableModels(SPI.Model.CompositeModel compositeModel, SPI.Model.AbstractInjectableModel model, Attribute scope, Type targetType, Type serviceType);
public InjectionTime GetInjectionTime(SPI.Model.AbstractInjectableModel model) { return(GetQualifierTypes(model).Any(tuple => tuple.Item2.ChangesDuringRuntime) ? InjectionTime.ON_METHOD_INVOKATION : InjectionTime.ON_CREATION); }