static InjectableInfo CreateForMember(MemberInfo memInfo, Type parentType) { var injectAttributes = memInfo.AllAttributes <InjectAttributeBase>().ToList(); Assert.That(injectAttributes.Count <= 1, "Found multiple 'Inject' attributes on type field '{0}' of type '{1}'. Field should only container one Inject attribute", memInfo.Name, parentType); var injectAttr = injectAttributes.SingleOrDefault(); object identifier = null; bool isOptional = false; InjectSources sourceType = InjectSources.Any; if (injectAttr != null) { identifier = injectAttr.Id; isOptional = injectAttr.Optional; sourceType = injectAttr.Source; } Type memberType = memInfo is FieldInfo ? ((FieldInfo)memInfo).FieldType : ((PropertyInfo)memInfo).PropertyType; var setter = GetSetter(parentType, memInfo); return(new InjectableInfo( isOptional, identifier, memInfo.Name, memberType, parentType, setter, null, sourceType)); }
static InjectableInfo CreateInjectableInfoForParam( Type parentType, ParameterInfo paramInfo) { var injectAttributes = paramInfo.AllAttributes <InjectAttributeBase>().ToList(); Assert.That(injectAttributes.Count <= 1, "Found multiple 'Inject' attributes on type parameter '{0}' of type '{1}'. Parameter should only have one", paramInfo.Name, parentType); var injectAttr = injectAttributes.SingleOrDefault(); object identifier = null; bool isOptional = false; InjectSources sourceType = InjectSources.Any; if (injectAttr != null) { identifier = injectAttr.Id; isOptional = injectAttr.Optional; sourceType = injectAttr.Source; } bool isOptionalWithADefaultValue = (paramInfo.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault; return(new InjectableInfo( isOptionalWithADefaultValue || isOptional, identifier, paramInfo.Name, paramInfo.ParameterType, parentType, null, isOptionalWithADefaultValue ? paramInfo.DefaultValue : null, sourceType)); }
static InjectableInfo CreateForMember(MemberInfo memInfo, Type parentType) { var injectAttributes = memInfo.AllAttributes <InjectAttributeBase>().ToList(); Assert.That(injectAttributes.Count <= 1, "Found multiple 'Inject' attributes on type field '{0}' of type '{1}'. Field should only container one Inject attribute", memInfo.Name, parentType); var injectAttr = injectAttributes.SingleOrDefault(); object identifier = null; bool isOptional = false; InjectSources sourceType = InjectSources.Any; if (injectAttr != null) { identifier = injectAttr.Id; isOptional = injectAttr.Optional; sourceType = injectAttr.Source; } Type memberType; Action <object, object> setter; if (memInfo is FieldInfo) { var fieldInfo = (FieldInfo)memInfo; setter = ((object injectable, object value) => fieldInfo.SetValue(injectable, value)); memberType = fieldInfo.FieldType; } else { Assert.That(memInfo is PropertyInfo); var propInfo = (PropertyInfo)memInfo; memberType = propInfo.PropertyType; #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR setter = ((object injectable, object value) => propInfo.SetValue(injectable, value, null)); #else if (propInfo.CanWrite) { setter = ((object injectable, object value) => propInfo.SetValue(injectable, value, null)); } else { setter = GetOnlyPropertySetter(parentType, propInfo.Name); } #endif } return(new InjectableInfo( isOptional, identifier, memInfo.Name, memberType, parentType, setter, null, sourceType)); }
public ConditionCopyNonLazyBinder FromResolveGetter <TObj>( object subIdentifier, Func <TObj, TContract> method, InjectSources source) { FactoryBindInfo.ProviderFunc = (container) => new GetterProvider <TObj, TContract>(subIdentifier, method, container, source, false); return(this); }
public ResolveProvider( Type contractType, DiContainer container, object identifier, bool isOptional, InjectSources source) { _contractType = contractType; _identifier = identifier; _container = container; _isOptional = isOptional; _source = source; }
public GetterProvider( object identifier, Func <TObj, TResult> method, DiContainer container, InjectSources sourceType, bool matchAll) { _container = container; _identifier = identifier; _method = method; _matchAll = matchAll; _sourceType = sourceType; }
public InjectableInfo( bool optional, object identifier, string memberName, Type memberType, object defaultValue, InjectSources sourceType) { Optional = optional; MemberType = memberType; MemberName = memberName; Identifier = identifier; DefaultValue = defaultValue; SourceType = sourceType; }
public InjectableInfo( bool optional, string identifier, string memberName, Type memberType, Type objectType, Action <object, object> setter, object defaultValue, InjectSources sourceType) { Optional = optional; Setter = setter; ObjectType = objectType; MemberType = memberType; MemberName = memberName; Identifier = identifier; DefaultValue = defaultValue; SourceType = sourceType; }
public InjectableInfo( bool optional, object identifier, string memberName, Type memberType, Type objectType, Action<object, object> setter, object defaultValue, InjectSources sourceType) { Optional = optional; Setter = setter; ObjectType = objectType; MemberType = memberType; MemberName = memberName; Identifier = identifier; DefaultValue = defaultValue; SourceType = sourceType; }
void SetDefaults() { _objectType = null; _parentContext = null; _objectInstance = null; _memberName = ""; _bindingId.Identifier = null; _bindingId.Type = null; _optional = false; _sourceType = InjectSources.Any; _fallBackValue = null; _container = null; }
protected ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveGetterBase <TObj, TResult>( object identifier, Func <TObj, TResult> method, InjectSources source, bool matchMultiple) { BindingUtil.AssertIsDerivedFromTypes(typeof(TResult), AllParentTypes); BindInfo.RequireExplicitScope = false; // Don't know how it's created so can't assume here that it violates AsSingle BindInfo.MarkAsCreationBinding = false; SubFinalizer = new ScopableBindingFinalizer( BindInfo, (container, type) => new GetterProvider <TObj, TResult>(identifier, method, container, source, matchMultiple)); return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo)); }
ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveInternal(object subIdentifier, bool matchAll, InjectSources source) { BindInfo.RequireExplicitScope = false; // Don't know how it's created so can't assume here that it violates AsSingle BindInfo.MarkAsCreationBinding = false; SubFinalizer = new ScopableBindingFinalizer( BindInfo, (container, type) => new ResolveProvider( type, container, subIdentifier, false, source, matchAll)); return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo)); }
public InjectContext( DiContainer container, Type memberType, string identifier, bool optional, Type objectType, object objectInstance, string memberName, InjectContext parentContext, string concreteIdentifier, object fallBackValue, InjectSources sourceType) { ObjectType = objectType; ObjectInstance = objectInstance; Identifier = identifier; ConcreteIdentifier = concreteIdentifier; MemberName = memberName; MemberType = memberType; Optional = optional; FallBackValue = fallBackValue; Container = container; BindingId = new BindingId(memberType, identifier); ParentContext = parentContext; SourceType = sourceType; }
public InjectOptionalAttribute(string identifier, InjectSources sourceType) { Identifier = identifier; SourceType = sourceType; IsOptional = true; }
public InjectOptionalAttribute(InjectSources sourceType) { SourceType = sourceType; IsOptional = true; }
public ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveAll(object subIdentifier, InjectSources source) { return(FromResolveInternal(subIdentifier, true, source)); }
public ScopeConditionCopyNonLazyBinder FromResolve(object subIdentifier, InjectSources source) { return(FromResolveInternal(subIdentifier, false, source)); }
public InjectAttribute(string identifier, InjectSources sourceType) { Identifier = identifier; SourceType = sourceType; }
public InjectAttribute(InjectSources sourceType) { SourceType = sourceType; }
public ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveAllGetter <TObj>(object identifier, Func <TObj, TContract> method, InjectSources source) { return(FromResolveGetterBase <TObj, TContract>(identifier, method, source, true)); }