protected virtual void ValidateInjectableModel(CompositeValidationResult result, CompositeModel compositeModel, AbstractInjectableModel model) { Int32 amount = model.GetAttributesMarkedWith(typeof(InjectionScopeAttribute)).Count; if (amount > 1) { result.InjectionValidationErrors.Add(ValidationErrorFactory.NewInjectionError("Only one injection permitted for field or parameter.", model)); } else { Attribute attr = model.InjectionScope; if (attr != null) { InjectionService injectionService = compositeModel.ApplicationModel.InjectionService; if (injectionService.HasFunctionalityFor(attr)) { if (!model.IsOptional) { var validationResult = injectionService.InjectionPossible(model); if (validationResult == null || !validationResult.InjectionPossible) { result.InjectionValidationErrors.Add(ValidationErrorFactory.NewInjectionError("Injection was not possible" + (validationResult == null ? "." : (": " + validationResult.AdditionalMessage)), model)); } } } else if (!model.IsOptional) { result.InjectionValidationErrors.Add(ValidationErrorFactory.NewInjectionError("Could not find injection functionality for attribute " + attr + ".", model)); } } else if (model is FieldModel) { result.InternalValidationErrors.Add(ValidationErrorFactory.NewInternalError("Injection attribute was null", model)); } } }
private static IEnumerable <Tuple <Attribute, ServiceQualifierAttribute> > GetQualifierTypes(AbstractInjectableModel model) { return(model.GetAttributesMarkedWith(typeof(ServiceQualifierAttribute)) .Select(attr => Tuple.Create(attr, (ServiceQualifierAttribute)model.GetAttributesOfAttribute(attr.GetType())[typeof(ServiceQualifierAttribute)][0]))); }