예제 #1
0
        public IEnumerable <IBinding> Resolve(Multimap <Type, IBinding> bindings, Type service)
        {
            Type configObjectType;

            if (ConfigObjectProvider.IsConfigObject(service))
            {
                configObjectType = service;
            }
            else if (ConfigObjectProvider.IsSourceBlock(service))
            {
                configObjectType = service.GetGenericArguments().Single();
            }
            else
            {
                return(Enumerable.Empty <IBinding>());
            }

            var provider = ProviderPerType.GetOrAdd(configObjectType, x => new ConfigObjectProvider());

            return(new[]
            {
                new Binding(service)
                {
                    ProviderCallback = ctx => provider,
                    ScopeCallback = StandardScopeCallbacks.Transient
                }
            });
        }
예제 #2
0
        public IEnumerable <IBinding> Resolve(Multimap <Type, IBinding> bindings, Type service)
        {
            ConfigObjectProvider provider;

            if (IsConfigObject(service))
            {
                provider = new ConfigObjectProvider(false);
            }
            else if (service.IsGenericType && service.GetGenericTypeDefinition() == typeof(ISourceBlock <>) &&
                     IsConfigObject(service.GetGenericArguments().Single()) && bindings[service].Any() == false)
            {
                provider = new ConfigObjectProvider(true);
            }
            else
            {
                return(Enumerable.Empty <IBinding>());
            }


            return(new[]
            {
                new Binding(service)
                {
                    ProviderCallback = ctx => provider,
                    ScopeCallback = StandardScopeCallbacks.Transient
                }
            });
        }