コード例 #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);
        }
コード例 #2
0
ファイル: MultiRegistration.cs プロジェクト: martindrlik/BTDB
 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);
         }
     }
 }