Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 public ResolveProvider(
     Type contractType, DiContainer container, object identifier,
     bool isOptional, InjectSources source)
 {
     _contractType = contractType;
     _identifier   = identifier;
     _container    = container;
     _isOptional   = isOptional;
     _source       = source;
 }
Esempio n. 6
0
 public GetterProvider(
     object identifier, Func <TObj, TResult> method,
     DiContainer container, InjectSources sourceType, bool matchAll)
 {
     _container  = container;
     _identifier = identifier;
     _method     = method;
     _matchAll   = matchAll;
     _sourceType = sourceType;
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
 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;
 }
Esempio n. 10
0
 void SetDefaults()
 {
     _objectType           = null;
     _parentContext        = null;
     _objectInstance       = null;
     _memberName           = "";
     _bindingId.Identifier = null;
     _bindingId.Type       = null;
     _optional             = false;
     _sourceType           = InjectSources.Any;
     _fallBackValue        = null;
     _container            = null;
 }
Esempio n. 11
0
        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));
        }
Esempio n. 13
0
 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;
 }
Esempio n. 14
0
 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;
 }
Esempio n. 15
0
 public InjectOptionalAttribute(string identifier, InjectSources sourceType)
 {
     Identifier = identifier;
     SourceType = sourceType;
     IsOptional = true;
 }
Esempio n. 16
0
 public InjectOptionalAttribute(InjectSources sourceType)
 {
     SourceType = sourceType;
     IsOptional = true;
 }
Esempio n. 17
0
 public InjectOptionalAttribute(string identifier, InjectSources sourceType)
 {
     Identifier = identifier;
     SourceType = sourceType;
     IsOptional = true;
 }
Esempio n. 18
0
 public ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveAll(object subIdentifier, InjectSources source)
 {
     return(FromResolveInternal(subIdentifier, true, source));
 }
Esempio n. 19
0
 public ScopeConditionCopyNonLazyBinder FromResolve(object subIdentifier, InjectSources source)
 {
     return(FromResolveInternal(subIdentifier, false, source));
 }
Esempio n. 20
0
 public InjectAttribute(string identifier, InjectSources sourceType)
 {
     Identifier = identifier;
     SourceType = sourceType;
 }
Esempio n. 21
0
 public InjectAttribute(InjectSources sourceType)
 {
     SourceType = sourceType;
 }
Esempio n. 22
0
 public InjectOptionalAttribute(InjectSources sourceType)
 {
     SourceType = sourceType;
     IsOptional = true;
 }
Esempio n. 23
0
 public InjectAttribute(string identifier, InjectSources sourceType)
 {
     Identifier = identifier;
     SourceType = sourceType;
 }
Esempio n. 24
0
 public ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveAllGetter <TObj>(object identifier, Func <TObj, TContract> method, InjectSources source)
 {
     return(FromResolveGetterBase <TObj, TContract>(identifier, method, source, true));
 }
Esempio n. 25
0
 public InjectAttribute(InjectSources sourceType)
 {
     SourceType = sourceType;
 }