Ejemplo n.º 1
0
        public static List <IInstaller> InstallInstallers(DiContainer container)
        {
            var uninstalled = container.ResolveMany <IInstaller>();

            var allInstallers = new List <IInstaller>();

            while (!uninstalled.IsEmpty())
            {
                container.ReleaseBindings <IInstaller>();

                foreach (var installer in uninstalled)
                {
                    installer.InstallBindings();
                    allInstallers.Add(installer);
                }

                uninstalled = container.ResolveMany <IInstaller>();
            }

            return(allInstallers);
        }
Ejemplo n.º 2
0
        object ResolveFromType(
            ResolveContext context, object injectable, InjectableInfo injectInfo)
        {
            if (_container.HasBinding(injectInfo.ContractType, context))
            {
                return(_container.Resolve(injectInfo.ContractType, context));
            }

            // If it's a list it might map to a collection
            if (ReflectionUtil.IsGenericList(injectInfo.ContractType))
            {
                var subType = injectInfo.ContractType.GetGenericArguments().Single();
                return(_container.ResolveMany(subType, context, injectInfo.Optional));
            }

            if (!injectInfo.Optional)
            {
                throw new ZenjectResolveException(
                          "Unable to find field with type '{0}' when injecting dependencies into '{1}'. \nObject graph:\n {2}"
                          .With(injectInfo.ContractType, injectable, _container.GetCurrentObjectGraph()));
            }

            return(null);
        }