protected IReadOnlyList <IRegistration> BuildRegistrations()
        {
            var registrations = new IRegistration[registrationBuilders.Count + (ContainerExposed ? 1 : 0)];

#if VCONTAINER_PARALLEL_CONTAINER_BUILD
            Parallel.For(0, registrationBuilders.Count, i =>
            {
                registrations[i] = registrationBuilders[i].Build();
            });
#else
            for (var i = 0; i < registrationBuilders.Count; i++)
            {
                registrations[i] = registrationBuilders[i].Build();
            }
#endif
            if (ContainerExposed)
            {
                registrations[registrations.Length - 1] = ContainerRegistration.Default;
            }

#if VCONTAINER_PARALLEL_CONTAINER_BUILD
            Parallel.For(0, registrations.Count, i =>
            {
                TypeAnalyzer.CheckCircularDependency(registrations[i].ImplementationType);
            });
#else
            foreach (var x in registrations)
            {
                TypeAnalyzer.CheckCircularDependency(x.ImplementationType);
            }
#endif
            return(registrations);
        }
        protected IReadOnlyList <IRegistration> BuildRegistrations()
        {
#if VCONTAINER_PARALLEL_CONTAINER_BUILD
            var a = new IRegistration[registrationBuilders.Count];
            Parallel.For(0, registrationBuilders.Count, i =>
            {
                a[i] = registrationBuilders[i].Build();
            });

            var registrations = new List <IRegistration>(a);
#else
            var registrations = new List <IRegistration>(registrationBuilders.Count);
            foreach (var registrationBuilder in registrationBuilders)
            {
                registrations.Add(registrationBuilder.Build());
            }
#endif

#if VCONTAINER_PARALLEL_CONTAINER_BUILD
            Parallel.For(0, registrations.Count, i =>
            {
                TypeAnalyzer.CheckCircularDependency(registrations[i].ImplementationType);
            });
#else
            foreach (var x in registrations)
            {
                TypeAnalyzer.CheckCircularDependency(x.ImplementationType);
            }
#endif
            if (containerRegistered)
            {
                registrations.Add(ContainerRegistration.Default);
            }
            return(registrations);
        }
Example #3
0
        protected (IReadOnlyList <IRegistration>, IReadOnlyList <(IRegistration, Action <IRegistration, IObjectResolver>)>) BuildRegistrations()
        {
            var registrations = new IRegistration[registrationBuilders.Count + (ContainerExposed ? 1 : 0)];
            var callbacks     = new List <(IRegistration, Action <IRegistration, IObjectResolver>)>(registrations.Length);

#if VCONTAINER_PARALLEL_CONTAINER_BUILD
            Parallel.For(0, registrationBuilders.Count, i =>
            {
                var registrationBuilder = registrationBuilders[i];
                var registration        = registrationBuilder.Build();
                registrations[i]        = registration;

                if (registrationBuilder.BuildCallback is Action <IRegistration, IObjectResolver> callback)
                {
                    callbacks.Add((registration, callback));
                }
            });
#else
            for (var i = 0; i < registrationBuilders.Count; i++)
            {
                var registrationBuilder = registrationBuilders[i];
                var registration        = registrationBuilder.Build();
                registrations[i] = registration;

                if (registrationBuilder.BuildCallback is Action <IRegistration, IObjectResolver> callback)
                {
                    callbacks.Add((registration, callback));
                }
            }
#endif
            if (ContainerExposed)
            {
                registrations[registrations.Length - 1] = ContainerRegistration.Default;
            }

#if VCONTAINER_PARALLEL_CONTAINER_BUILD
            Parallel.For(0, registrations.Count, i =>
            {
                TypeAnalyzer.CheckCircularDependency(registrations[i].ImplementationType);
            });
#else
            foreach (var x in registrations)
            {
                TypeAnalyzer.CheckCircularDependency(x.ImplementationType);
            }
#endif
            return(registrations, callbacks);
        }