Exemple #1
0
        public void Register(ContanerRegistrationContext context)
        {
            ICReg reg;
            var   possibleConstructors = _constructorTrait.ReturnPossibleConstructors(_implementationType).ToList();
            var   bestConstructor      = _constructorTrait.ChooseConstructor(_implementationType, possibleConstructors);

            if (bestConstructor == null)
            {
                throw new ArgumentException($"Cannot find public constructor for {_implementationType.FullName}");
            }
            switch (_liveScopeTrait.Lifetime)
            {
            case Lifetime.AlwaysNew:
                reg = new AlwaysNewImpl(_implementationType, bestConstructor);
                break;

            case Lifetime.Singleton:
                reg = new SingletonImpl(_implementationType, new AlwaysNewImpl(_implementationType, bestConstructor), context.SingletonCount);
                context.SingletonCount++;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            context.AddCReg(_asTrait.GetAsTypesFor(_implementationType), _asTrait.PreserveExistingDefaults, reg);
        }
        public void Register(ContanerRegistrationContext context)
        {
            ICRegILGen reg = new FactoryWithContainerParamImpl(context.AddInstance(_factory), _implementationType);

            if (_liveScopeTrait.Lifetime == Lifetime.Singleton)
            {
                reg = new SingletonImpl(_implementationType, reg, context.SingletonCount);
                context.SingletonCount++;
            }
            context.AddCReg(_asTrait.GetAsTypesFor(_implementationType), _asTrait.PreserveExistingDefaults, (ICReg)reg);
        }
Exemple #3
0
        // ReSharper restore MemberCanBePrivate.Global

        internal ContainerImpl(IEnumerable<IRegistration> registrations)
        {
            var context = new ContanerRegistrationContext(this, Registrations);
            foreach (var registration in registrations)
            {
                ((IContanerRegistration)registration).Register(context);
            }
            SingletonLocks = new object[context.SingletonCount];
            for (int i = 0; i < context.SingletonCount; i++)
            {
                SingletonLocks[i] = new object();
            }
            Singletons = new object[context.SingletonCount];
            Instances = context.Instances.ToArray();
            context.AddCReg(Enumerable.Repeat(new KeyAndType(null, typeof(IContainer)), 1), true, new ContainerInjectImpl());
        }
Exemple #4
0
        // ReSharper restore MemberCanBePrivate.Global

        internal ContainerImpl(IEnumerable <IRegistration> registrations)
        {
            var context = new ContanerRegistrationContext(this, Registrations);

            foreach (var registration in registrations)
            {
                ((IContanerRegistration)registration).Register(context);
            }
            SingletonLocks = new object[context.SingletonCount];
            for (int i = 0; i < context.SingletonCount; i++)
            {
                SingletonLocks[i] = new object();
            }
            Singletons = new object[context.SingletonCount];
            Instances  = context.Instances.ToArray();
            context.AddCReg(Enumerable.Repeat(new KeyAndType(null, typeof(IContainer)), 1), true, new ContainerInjectImpl());
        }
        public void Register(ContanerRegistrationContext context)
        {
            var reg = new InstanceImpl(_instance, context.AddInstance(_instance));

            context.AddCReg(_asTrait.GetAsTypesFor(_implementationType), _asTrait.PreserveExistingDefaults, reg);
        }