ResolveAllBindings() public method

public ResolveAllBindings ( ) : Binding>.IDictionary
return Binding>.IDictionary
Esempio n. 1
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;
        }
Esempio n. 2
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, plugin, 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 entryPointType in module.EntryPoints)
                {
                    var key = entryPointType.Resolve().IsInterface
                                  ? CompilerKeys.ForType(entryPointType)
                                  : CompilerKeys.GetMemberKey(entryPointType);
                    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));
                    }

                    addTo.Add(binding.ProviderKey, binding);
                }
            }

            resolver.InstallBindings(bindings);
            resolver.InstallBindings(overrides);
            var allBindings = resolver.ResolveAllBindings();
            return hasError ? null : allBindings;
        }