Beispiel #1
0
        void ISelector.Populate(IServiceCollection services, RegistrationStrategy strategy)
        {
            if (!Lifetime.HasValue)
            {
                Lifetime = ServiceLifetime.Transient;
            }

            strategy = strategy ?? RegistrationStrategy.Append;

            foreach (var typeMap in TypeMaps)
            {
                foreach (var serviceType in typeMap.ServiceTypes)
                {
                    var implementationType = typeMap.ImplementationType;

                    if (!implementationType.IsAssignableTo(serviceType))
                    {
                        throw new InvalidOperationException($@"Type ""{implementationType.FullName}"" is not assignable to ""${serviceType.FullName}"".");
                    }

                    var descriptor = new ServiceDescriptor(serviceType, implementationType, Lifetime.Value);

                    strategy.Apply(services, descriptor);
                }
            }
        }
Beispiel #2
0
 void ISelector.Populate(IServiceCollection services, RegistrationStrategy registrationStrategy)
 {
     foreach (var selector in Selectors)
     {
         selector.Populate(services, registrationStrategy);
     }
 }
        public IServiceTypeSelector UsingRegistrationStrategy(RegistrationStrategy registrationStrategy)
        {
            Preconditions.NotNull(registrationStrategy, nameof(registrationStrategy));

            RegistrationStrategy = registrationStrategy;
            return(this);
        }
        void ISelector.Populate(IServiceCollection services, RegistrationStrategy registrationStrategy)
        {
            var strategy = registrationStrategy ?? RegistrationStrategy.Append;

            foreach (var type in Types)
            {
                var typeInfo = type.GetTypeInfo();

                var attributes = typeInfo.GetCustomAttributes <ServiceDescriptorAttribute>().ToArray();

                // Check if the type has multiple attributes with same ServiceType.
                var duplicates = GetDuplicates(attributes);

                if (duplicates.Any())
                {
                    throw new InvalidOperationException($@"Type ""{type.FullName}"" has multiple ServiceDescriptor attributes with the same service type.");
                }

                foreach (var attribute in attributes)
                {
                    var serviceTypes = attribute.GetServiceTypes(type);

                    foreach (var serviceType in serviceTypes)
                    {
                        var descriptor = new ServiceDescriptor(serviceType, type, attribute.Lifetime);

                        strategy.Apply(services, descriptor);
                    }
                }
            }
        }
        void ISelector.Populate(IServiceCollection services, RegistrationStrategy registrationStrategy)
        {
            if (Selectors.Count == 0)
            {
                AddClasses();
            }

            foreach (var selector in Selectors)
            {
                selector.Populate(services, registrationStrategy);
            }
        }
        void ISelector.Populate(IServiceCollection services, RegistrationStrategy registrationStrategy)
        {
            if (Selectors.Count == 0)
            {
                AsSelf();
            }

            var strategy = RegistrationStrategy ?? registrationStrategy;

            foreach (var selector in Selectors)
            {
                selector.Populate(services, strategy);
            }
        }
Beispiel #7
0
 public IServiceTypeSelector UsingRegistrationStrategy(RegistrationStrategy registrationStrategy)
 {
     return(Inner.UsingRegistrationStrategy(registrationStrategy));
 }