Exemplo n.º 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);
        }
Exemplo n.º 2
0
 public void Register(ContanerRegistrationContext context)
 {
     foreach (var assembly in _froms)
     {
         foreach (var type in assembly.GetTypes())
         {
             if (!type.IsClass)
             {
                 continue;
             }
             if (type.IsAbstract)
             {
                 continue;
             }
             if (type.IsGenericTypeDefinition)
             {
                 continue;
             }
             if (type.IsDelegate())
             {
                 continue;
             }
             if (!_scanTrait.MatchFilter(type))
             {
                 continue;
             }
             if (_constructorTrait.ChooseConstructor(type, _constructorTrait.ReturnPossibleConstructors(type)) == null)
             {
                 continue;
             }
             ((IContanerRegistration) new SingleRegistration(type, _asTrait, _liveScopeTrait, _constructorTrait, _propertiesTrait)).Register(context);
         }
     }
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 5
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());
        }
Exemplo n.º 6
0
        public void Register(ContanerRegistrationContext context)
        {
            var reg = new InstanceImpl(_instance, context.AddInstance(_instance));

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