Inheritance: SetBindingBase
Beispiel #1
0
        public static void Add(IDictionary <string, Binding> bindings, string key, CompilerProvidesBinding binding)
        {
            Binding            previous;
            CompilerSetBinding setBinding;

            if (bindings.TryGetValue(key, out previous))
            {
                setBinding = previous as CompilerSetBinding;

                if (setBinding == null)
                {
                    throw new ValidationException("Duplicates:\n" + previous + "\n" + binding);
                }

                setBinding.IsLibrary = setBinding.IsLibrary && binding.IsLibrary;
            }
            else
            {
                bindings[key] = setBinding = new CompilerSetBinding(key, binding.RequiredBy)
                {
                    IsLibrary = binding.IsLibrary
                };
            }

            setBinding.Contributors.Add(Resolver.Scope(binding));
        }
        public static void Add(IDictionary<string, Binding> bindings, string key, CompilerProvidesBinding binding)
        {
            Binding previous;
            CompilerSetBinding setBinding;

            if (bindings.TryGetValue(key, out previous))
            {
                setBinding = previous as CompilerSetBinding;

                if (setBinding == null)
                {
                    throw new ValidationException("Duplicates:\n" + previous + "\n" + binding);
                }

                setBinding.IsLibrary = setBinding.IsLibrary && binding.IsLibrary;
            }
            else
            {
                bindings[key] = setBinding = new CompilerSetBinding(key, binding.RequiredBy)
                {
                    IsLibrary = binding.IsLibrary
                };
            }

            setBinding.Contributors.Add(Resolver.Scope(binding));
        }
Beispiel #3
0
        private IDictionary <string, Binding> ProcessCompleteModule(
            ModuleGenerator moduleGenerator,
            bool ignoreCompletenessErrors)
        {
            var bindings   = new Dictionary <string, Binding>(StringComparer.Ordinal);
            var overrides  = new Dictionary <string, Binding>(StringComparer.Ordinal);
            var allModules = new Dictionary <string, ModuleGenerator>(StringComparer.Ordinal);
            var hasError   = false;

            GatherIncludedModules(moduleGenerator, allModules, new Stack <string>());

            var resolver = new Resolver(null, loader, errors =>
            {
                if (ignoreCompletenessErrors)
                {
                    return;
                }

                hasError = true;
                foreach (var e in errors)
                {
                    errorReporter.LogError(e);
                }
            });

            foreach (var module in allModules.Values)
            {
                // Request entry-point bindings
                var addTo = module.IsOverride ? overrides : bindings;

                foreach (var injectType in module.Injects)
                {
                    var key = injectType.Resolve().IsInterface
                                  ? CompilerKeys.ForType(injectType)
                                  : CompilerKeys.GetMemberKey(injectType);

                    resolver.RequestBinding(key, module.ModuleType.FullName, false, true);
                }

                foreach (var providerGenerator in module.ProviderGenerators)
                {
                    var binding = new CompilerProvidesBinding(providerGenerator);

                    if (addTo.ContainsKey(binding.ProviderKey))
                    {
                        var message  = "Duplicate bindings for {0} in {1}{2}.";
                        var addendum = module.IsOverride ? "overriding module " : string.Empty;

                        throw new ValidationException(string.Format
                                                          (message, binding.ProviderKey, addendum, module.ModuleType.FullName));
                    }

                    switch (providerGenerator.ProvidesType)
                    {
                    case ProvidesType.Default:
                        addTo.Add(binding.ProviderKey, binding);
                        break;

                    case ProvidesType.Set:
                        var setKey = CompilerKeys.GetSetKey(binding.ProviderKey);
                        CompilerSetBinding.Add(addTo, setKey, binding);
                        break;

                    default:
                        throw new ArgumentException("Unknown ProvidesType value: " + providerGenerator.ProvidesType);
                    }
                }
            }

            resolver.InstallBindings(bindings);
            resolver.InstallBindings(overrides);
            var allBindings = resolver.ResolveAllBindings();

            return(!hasError ? allBindings : null);
        }