Esempio n. 1
0
        public static Binding Scope(Binding binding)
        {
            if (!binding.IsSingleton)
                return binding;

            if (binding is SingletonBinding)
                throw new ArgumentException("ASSERT FALSE: If it's already a SingletonBinding, why are we here?");

            return new SingletonBinding(binding);
        }
Esempio n. 2
0
        public override void Resolve(Resolver resolver)
        {
            ctorBindings = new List<Binding>(generator.CtorParams.Count);
            foreach (var p in generator.CtorParams) {
                ctorBindings.Add(resolver.RequestBinding(p.Key, generator.InjectedType.FullName));
            }

            propertyBindings = new List<Binding>(generator.InjectableProperties.Count);
            foreach (var p in generator.InjectableProperties) {
                propertyBindings.Add(resolver.RequestBinding(p.Key, generator.InjectedType.FullName));
            }

            if (generator.BaseTypeKey != null) {
                baseTypeBinding = resolver.RequestBinding(generator.BaseTypeKey, generator.BaseTypeKey, false);
            }
        }
 public override void Resolve(Resolver resolver)
 {
     elementBinding = resolver.RequestBinding(elementKey, RequiredBy);
 }
Esempio n. 4
0
        private void AddBindingToDictionary(Binding binding)
        {
            if (binding.ProviderKey != null)
            {
                AddBindingIfAbsent(binding, binding.ProviderKey);
            }

            if (binding.MembersKey != null)
            {
                AddBindingIfAbsent(binding, binding.MembersKey);
            }
        }
Esempio n. 5
0
 private void AddBindingIfAbsent(Binding binding, string key)
 {
     if (!bindings.ContainsKey(key))
     {
         bindings.Add(key, binding);
     }
 }
 internal SingletonBinding(Binding binding)
     : base(binding.ProviderKey, binding.MembersKey, true, binding.RequiredBy)
 {
     this.binding = binding;
 }
Esempio n. 7
0
        private static CompilerProvidesBinding Unwrap(Binding binding)
        {
            var providesBinding = binding as CompilerProvidesBinding;

            if (providesBinding != null)
            {
                return providesBinding;
            }

            var singleton = binding as SingletonBinding;
            if (singleton != null)
            {
                return Unwrap(singleton.DelegateBinding);
            }

            throw new ArgumentException("Not a provides binding: " + binding.ProviderKey);
        }
Esempio n. 8
0
        private static ProviderMethodBindingBase CastOrUnwrapBinding(Binding binding)
        {
            var providerMethodBindingBase = binding as ProviderMethodBindingBase;
            if (providerMethodBindingBase != null) {
                return providerMethodBindingBase;
            }

            var singletonBinding = binding as SingletonBinding;
            if (singletonBinding != null) {
                providerMethodBindingBase = singletonBinding.DelegateBinding as ProviderMethodBindingBase;
            }

            if (providerMethodBindingBase == null) {
                throw new InvalidOperationException("WTF, how is an unused binding not a provides binding?");
            }

            return providerMethodBindingBase;
        }