static InjectableInfo CreateForMember(MemberInfo memInfo, Type enclosingType) { var injectAttr = memInfo.AllAttributes <InjectAttribute>().FirstOrDefault(); var info = new InjectableInfo() { Optional = memInfo.HasAttribute(typeof(InjectOptionalAttribute)), Identifier = (injectAttr == null ? null : injectAttr.Identifier), SourceName = memInfo.Name, EnclosingType = enclosingType, }; if (memInfo is FieldInfo) { var fieldInfo = (FieldInfo)memInfo; info.Setter = ((object injectable, object value) => fieldInfo.SetValue(injectable, value)); info.ContractType = fieldInfo.FieldType; } else { Assert.That(memInfo is PropertyInfo); var propInfo = (PropertyInfo)memInfo; info.Setter = ((object injectable, object value) => propInfo.SetValue(injectable, value, null)); info.ContractType = propInfo.PropertyType; } return(info); }
public InjectMemberInfo( ZenMemberSetterMethod setter, InjectableInfo info) { Setter = setter; Info = info; }
internal object Resolve( InjectableInfo injectInfo, object targetInstance) { var context = new InjectContext( this, injectInfo, LookupsInProgress.ToList(), targetInstance); return(Resolve(injectInfo.ContractType, context)); }
internal InjectContext( DiContainer container, InjectableInfo injectInfo, List <Type> parents, object targetInstance) { Container = container; Optional = injectInfo.Optional; Identifier = injectInfo.Identifier; SourceName = injectInfo.SourceName; EnclosingType = injectInfo.EnclosingType; EnclosingInstance = targetInstance; ParentTypes = parents; }
DiContainer CreateTempContainer(List <TypeValuePair> args) { DiContainer tempSubContainer = Container.CreateSubContainer(); ZenjectTypeInfo installerInjectables = TypeAnalyzer.GetInfo(_installerType); foreach (TypeValuePair argPair in args) { // We need to intelligently match on the exact parameters here to avoid the issue // brought up in github issue #217 InjectableInfo match = installerInjectables.AllInjectables .Where(x => argPair.Type.DerivesFromOrEqual(x.MemberType)) .OrderBy(x => ZenUtilInternal.GetInheritanceDelta(argPair.Type, x.MemberType)).FirstOrDefault(); Assert.That(match != null, "Could not find match for argument type '{0}' when injecting into sub container installer '{1}'", argPair.Type, _installerType); tempSubContainer.Bind(match.MemberType) .FromInstance(argPair.Value).WhenInjectedInto(_installerType); } return(tempSubContainer); }
internal object Resolve(InjectableInfo injectInfo) { return(Resolve(injectInfo, null)); }