예제 #1
0
        private void IterateAndRegister(ILookup <RegistrationInfo, Type> lookup, Func <Type, bool> typePredicate,
                                        RegistrationTarget target)
        {
            if (lookup == null || typePredicate == null)
            {
                return;
            }

            var serviceTypeCondition = TargetResolver.Resolve(target);

            foreach (var group in lookup)
            {
                if (group.Key.Matches(RegistrationLifeTime.None))
                {
                    continue;
                }

                var matchingTypes = group.Where(t => t != null)
                                    .Where(typePredicate);

                var lifetime = group.Key.LifeTime.ToContainerLifeTime();
                var key      = group.Key.Key;

                foreach (Type t in matchingTypes)
                {
                    var serviceType = t.GetInterfaces().First().IsGenericType ? t.GetInterfaces().First().GetGenericTypeDefinition() : t.GetInterfaces().First();
                    _container.Register(serviceType, t, lifestyle: lifetime);
                }
            }
        }
예제 #2
0
        public IRegistrationContainer Register(Type concreteType, RegistrationTarget target,
                                               RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient, string key = null, bool shouldReplace = false)
        {
            var serviceTypeCondition = TargetResolver.Resolve(target);

            //_container.Register(concreteType);
            //_container.Register( concreteType.UnderlyingSystemType, () => concreteType, registrationLifeTime.ToContainerLifeTime());
            _container.Register(concreteType.GetType(), () => concreteType, registrationLifeTime.ToContainerLifeTime());
            return(this);
        }