Exemple #1
0
        /// <summary>
        /// Creates the IoC container
        /// </summary>
        /// <param name="queueType">Type of the queue.</param>
        /// <param name="registerService">The user defined service overrides.</param>
        /// <param name="queue">The queue.</param>
        /// <param name="connection">The connection.</param>
        /// <param name="register">The transport init module.</param>
        /// <param name="connectionType">Type of the connection.</param>
        /// <param name="registerServiceInternal">The internal registrations.</param>
        /// <param name="setOptions">The options.</param>
        /// <param name="registrations">The registrations for job queue creation.</param>
        /// <returns>
        /// a new container
        /// </returns>
        public IContainer Create(QueueContexts queueType,
                                 Action <IContainer> registerService,
                                 string queue,
                                 string connection,
                                 T register,
                                 ConnectionTypes connectionType,
                                 Action <IContainer> registerServiceInternal,
                                 Action <IContainer> setOptions = null,
                                 JobQueueContainerRegistrations registrations = null)
        {
            lock (ContainerLocker.Locker) //thread safe issue with registration of decorators; should not be needed, but have found no other solution
            {
                var container = new Container();
                container.Options.ResolveUnregisteredConcreteTypes = true;
                var containerWrapper = new ContainerWrapper(container);

                containerWrapper.Register(() => new QueueContext(queueType), LifeStyles.Singleton);
                if (registrations != null)
                {
                    containerWrapper.Register(() => registrations, LifeStyles.Singleton);
                }
                else
                {
                    containerWrapper.Register(() => new JobQueueContainerRegistrations(null, null, null, null), LifeStyles.Singleton);
                }

                var type = GetRegistrationType(register);

                if (!string.IsNullOrWhiteSpace(queue) && !string.IsNullOrWhiteSpace(connection))
                {
                    ComponentRegistration.RegisterDefaults(containerWrapper, type);
                }
                else
                {
                    if (queueType == QueueContexts.JobScheduler)
                    {
                        ComponentRegistration.RegisterDefaultsForJobScheduler(containerWrapper);
                    }
                    else
                    {
                        ComponentRegistration.RegisterDefaultsForScheduler(containerWrapper);
                    }
                }

                //allow creating internal queues
                containerWrapper.Register <IQueueContainer>(() => new QueueContainer <T>(),
                                                            LifeStyles.Singleton);

                // Enable overriding
                container.Options.AllowOverridingRegistrations = true;

                //register transport specific objects
                register.RegisterImplementations(containerWrapper, type, connection, queue);

                //register our internal overrides from outside this container
                registerServiceInternal(containerWrapper);

                //register caller overrides
                registerService(containerWrapper);

                //register conditional fall backs
                container.Options.AllowOverridingRegistrations = false;
                ComponentRegistration.RegisterFallbacks(containerWrapper, type);

                //disable auto verify - we will verify below
                container.Options.EnableAutoVerification = false;

                //allow specific warnings to be disabled
                register.SuppressWarningsIfNeeded(containerWrapper, type);

                //suppress IoC warnings that we are explicitly handling
                ComponentRegistration.SuppressWarningsIfNeeded(containerWrapper, type);

                //set the log provider, if one was provided
                //if no explicit log provider was set, we will use lib log defaults
                var logProvider = container.GetInstance <ILogProvider>();
                if (!(logProvider is NoSpecifiedLogProvider))
                {
                    LogProvider.SetCurrentLogProvider(logProvider);
                    var factory = container.GetInstance <ILogFactory>();
                    factory.Create();
                }

                //verify the container configuration.
                container.Verify();

                //default polices
                ComponentRegistration.SetupDefaultPolicies(containerWrapper, type);

                //allow the transport to set defaults if needed
                register.SetDefaultsIfNeeded(containerWrapper, type, connectionType);

                //allow user override or setting of additional options
                setOptions?.Invoke(containerWrapper);

                return(containerWrapper);
            }
        }
Exemple #2
0
 /// <summary>
 /// Creates the IoC container
 /// </summary>
 /// <param name="queueType">Type of the queue.</param>
 /// <param name="registerService">The user defined service overrides.</param>
 /// <param name="register">The transport init module.</param>
 /// <param name="registerServiceInternal">The internal registrations.</param>
 /// <param name="setOptions">The options.</param>
 /// <param name="registrations">The registrations for job queue creation.</param>
 /// <returns>
 /// a new container
 /// </returns>
 public IContainer Create(QueueContexts queueType, Action <IContainer> registerService, T register, Action <IContainer> registerServiceInternal, Action <IContainer> setOptions = null, JobQueueContainerRegistrations registrations = null)
 {
     return(Create(queueType, registerService, string.Empty, string.Empty, register, ConnectionTypes.NotSpecified, registerServiceInternal, setOptions, registrations));
 }