public static InjectionInfo Parse(Type type, BindingFlags bindingFlags, InjectorFlags injectorFlags)
        {
            var info = new InjectionInfo();

            if (bindingFlags.Has(BindingFlags.SetProperty))
            {
                ParsePropertyAttributes <Inject>(type, info);
            }

            if (bindingFlags.Has(BindingFlags.SetField))
            {
                ParseFieldAttributes <Inject>(type, info);
            }

            if (!injectorFlags.Has(InjectorFlags.PreventPostInjection))
            {
                ParseMethodAttributes <PostInjection>(type, info);
            }

            if (!injectorFlags.Has(InjectorFlags.PreventCleanup))
            {
                ParseMethodAttributes <Cleanup>(type, info);
            }

            return(info);
        }
示例#2
0
        private InjectionInfo RetrieveInfo(Type type, BindingFlags bindingFlags, InjectorFlags injectorFlag)
        {
            InjectionInfo info;

            if (!infoMap.TryGetValue(type, out info))
            {
                infoMap[type] = info = InfoParser.Parse(type, bindingFlags, injectorFlag);
            }

            return(info);
        }
示例#3
0
        internal void Inject <T> (T instance,
                                  Func <Type, object, object> getInstanceHandler,
                                  Action <Action> cleanupHandler,
                                  BindingFlags bindingFlags,
                                  InjectorFlags injectorFlags)
        {
            var key  = instance.GetType();
            var info = RetrieveInfo(key, bindingFlags, injectorFlags);

            if (info.HasInjections())
            {
                InjectInstances(getInstanceHandler, instance, key, info.Injections, bindingFlags);
            }

            if (info.HasCalls <PostInjection>())
            {
                InvokeMethods(instance, info.GetCalls <PostInjection>());
            }

            if (info.HasCalls <Cleanup>())
            {
                RegisterCleanups(cleanupHandler, instance, info.GetCalls <Cleanup>());
            }
        }
示例#4
0
 public static bool Has(this InjectorFlags flags, InjectorFlags flag)
 {
     return((flags & flag) != 0);
 }