Exemplo n.º 1
0
        public void CreateGenerators(ModuleWeaver weaver)
        {
            if (moduleDefinition.AssemblyReferences.All(reference => reference.Name != "Stiletto"))
            {
                UsesStiletto = false;
                return;
            }

            var moduleTypes = new List <TypeDefinition>();
            var injectTypes = new List <TypeDefinition>();

            foreach (var t in moduleDefinition.GetTypes())
            {
                if (IsModule(t))
                {
                    if (weaver.ExcludedClasses.Contains(t.FullName))
                    {
                        continue;
                    }

                    moduleTypes.Add(t);
                }
                else if (IsInject(t))
                {
                    if (weaver.ExcludedClasses.Contains(t.FullName))
                    {
                        continue;
                    }

                    injectTypes.Add(t);
                }
            }

            moduleGenerators.AddRange(moduleTypes
                                      .Select(m => new ModuleGenerator(moduleDefinition, references, m)));

            GatherInjectBindings(
                injectTypes,
                moduleGenerators.SelectMany(m => m.EntryPoints));

            foreach (var g in injectGenerators)
            {
                // We need to validate the inject binding generators to
                // discover their injectable constructors and properties,
                // which we need to have to get lazy and IProvider bindings.
                g.Weaver = weaver;
                g.Validate(errorReporter);
            }

            GatherParameterizedBindings();

            UsesStiletto = InjectGenerators.Any() ||
                           ModuleGenerators.Any() ||
                           LazyGenerators.Any() ||
                           ProviderGenerators.Any();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates and validates any enqueued base-class generators that were enqueued.
        /// </summary>
        public void CreateBaseClassGenerators(ModuleWeaver weaver)
        {
            var injectedTypes = new HashSet <TypeDefinition>(InjectGenerators.Select(gen => gen.InjectedType));

            while (baseGeneratorQueue.Count > 0)
            {
                var typedef = baseGeneratorQueue.Dequeue();
                if (!injectedTypes.Add(typedef))
                {
                    continue;
                }

                var gen = new InjectBindingGenerator(moduleDefinition, references, typedef, false);
                gen.Weaver = weaver;
                gen.Validate(errorReporter);
                InjectGenerators.Add(gen);
            }
        }