Пример #1
0
        /// <summary>
        /// Create a new component registration.
        /// </summary>
        /// <param name="id">Unique identifier for the component.</param>
        /// <param name="activator">Activator used to activate instances.</param>
        /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
        /// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
        /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
        /// <param name="services">Services the component provides.</param>
        /// <param name="metadata">Data associated with the component.</param>
        public ComponentRegistration(
            Guid id,
            IInstanceActivator activator,
            IComponentLifetime lifetime,
            InstanceSharing sharing,
            InstanceOwnership ownership,
            IEnumerable <Service> services,
            IDictionary <string, object> metadata)
        {
            if (activator == null)
            {
                throw new ArgumentNullException(nameof(activator));
            }
            if (lifetime == null)
            {
                throw new ArgumentNullException(nameof(lifetime));
            }
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (metadata == null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            Id        = id;
            Activator = activator;
            Lifetime  = lifetime;
            Sharing   = sharing;
            Ownership = ownership;
            Services  = Enforce.ArgumentElementNotNull(services, nameof(services)).ToList();
            Metadata  = new Dictionary <string, object>(metadata);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComponentRegistration"/> class.
        /// </summary>
        /// <param name="id">Unique identifier for the component.</param>
        /// <param name="activator">Activator used to activate instances.</param>
        /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
        /// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
        /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
        /// <param name="pipelineBuilder">The resolve pipeline builder for the registration.</param>
        /// <param name="services">Services the component provides.</param>
        /// <param name="metadata">Data associated with the component.</param>
        /// <param name="options">The additional registration options.</param>
        public ComponentRegistration(
            Guid id,
            IInstanceActivator activator,
            IComponentLifetime lifetime,
            InstanceSharing sharing,
            InstanceOwnership ownership,
            IResolvePipelineBuilder pipelineBuilder,
            IEnumerable <Service> services,
            IDictionary <string, object?> metadata,
            RegistrationOptions options = RegistrationOptions.None)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            Id        = id;
            Activator = activator ?? throw new ArgumentNullException(nameof(activator));
            Lifetime  = lifetime ?? throw new ArgumentNullException(nameof(lifetime));
            Sharing   = sharing;
            Ownership = ownership;

            _lateBuildPipeline = pipelineBuilder;

            Services = Enforce.ArgumentElementNotNull(services, nameof(services));
            Metadata = metadata ?? throw new ArgumentNullException(nameof(metadata));
            Options  = options;
        }
Пример #3
0
        /// <summary>
        ///   Stops the event processor.  In case it isn't running, nothing happens.
        /// </summary>
        ///
        /// <returns>A task to be resolved on when the operation has completed.</returns>
        ///
        /// <remarks>
        ///   If overridden, the base class implementation must be explicitly called in order to make the event processor stop
        ///   running.
        /// </remarks>
        ///
        public virtual async Task StopAsync()
        {
            if (ActiveLoadBalancingTask != null)
            {
                await RunningTaskSemaphore.WaitAsync().ConfigureAwait(false);

                try
                {
                    if (ActiveLoadBalancingTask != null)
                    {
                        // Cancel the current running task.

                        RunningTaskTokenSource.Cancel();
                        RunningTaskTokenSource = null;

                        // Now that a cancellation request has been issued, wait for the running task to finish.  In case something
                        // unexpected happened and it stopped working midway, this is the moment we expect to catch an exception.

                        try
                        {
                            await ActiveLoadBalancingTask.ConfigureAwait(false);
                        }
                        catch (Exception ex) when(ex is TaskCanceledException || ex is OperationCanceledException)
                        {
                            // Nothing to do here.  These exceptions are expected.
                        }
                        catch (Exception)
                        {
                            // TODO: delegate the exception handling to an Exception Callback.  Instead of delegating it to the handler,
                            // should we surface it?
                        }

                        // Now that the task has finished, clean up what is left.  Stop and remove every partition processing task that is
                        // still running and clear our dictionaries.  ActivePartitionProcessors, ActivePartitionProcessorTokenSources and
                        // PartitionContexts are already cleared by the StopPartitionProcessingIfRunningAsync method.

                        await Task.WhenAll(ActivePartitionProcessors.Keys
                                           .Select(partitionId => StopPartitionProcessingIfRunningAsync(partitionId, ProcessingStoppedReason.Shutdown)))
                        .ConfigureAwait(false);

                        InstanceOwnership.Clear();

                        // TODO: once IsRunning is implemented, update the following comment.
                        // We need to wait until all tasks have stopped before making the load balancing task null.  If we did it sooner, we
                        // would have a race condition where the user could update the processing handlers while some pumps are still running.

                        ActiveLoadBalancingTask = null;
                    }
                }
                finally
                {
                    RunningTaskSemaphore.Release();
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComponentRegistration"/> class.
 /// </summary>
 /// <param name="id">Unique identifier for the component.</param>
 /// <param name="activator">Activator used to activate instances.</param>
 /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
 /// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
 /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
 /// <param name="services">Services the component provides.</param>
 /// <param name="metadata">Data associated with the component.</param>
 /// <param name="options">Contains options for the registration.</param>
 public ComponentRegistration(
     Guid id,
     IInstanceActivator activator,
     IComponentLifetime lifetime,
     InstanceSharing sharing,
     InstanceOwnership ownership,
     IEnumerable <Service> services,
     IDictionary <string, object?> metadata,
     RegistrationOptions options = RegistrationOptions.None)
     : this(id, activator, lifetime, sharing, ownership, new ResolvePipelineBuilder(PipelineType.Registration), services, metadata, options)
 {
 }
Пример #5
0
 /// <summary>
 /// Create a new component registration.
 /// </summary>
 /// <param name="id">Unique identifier for the component.</param>
 /// <param name="activator">Activator used to activate instances.</param>
 /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
 /// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
 /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
 /// <param name="services">Services the component provides.</param>
 /// <param name="metadata">Data associated with the component.</param>
 /// <param name="target">The component registration upon which this registration is based.</param>
 public ComponentRegistration(
     Guid id,
     IInstanceActivator activator,
     IComponentLifetime lifetime,
     InstanceSharing sharing,
     InstanceOwnership ownership,
     IEnumerable <Service> services,
     IDictionary <string, object> metadata,
     IComponentRegistration target)
     : this(id, activator, lifetime, sharing, ownership, services, metadata)
 {
     _target = Enforce.ArgumentNotNull(target, "target");
 }
Пример #6
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="System.Object" />
 ///     class.
 /// </summary>
 // ReSharper disable once UnusedMember.Global
 public ComponentRegistration(
     IComponentLifetime lifetime
     , InstanceSharing sharing
     , InstanceOwnership ownership
     , IComponentRegistration target
     )
 {
     Id        = Guid.NewGuid( );
     Lifetime  = lifetime;
     Sharing   = sharing;
     Ownership = ownership;
     Target    = target;
 }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComponentRegistration"/> class.
        /// </summary>
        /// <param name="id">Unique identifier for the component.</param>
        /// <param name="activator">Activator used to activate instances.</param>
        /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
        /// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
        /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
        /// <param name="pipelineBuilder">The resolve pipeline builder for the registration.</param>
        /// <param name="services">Services the component provides.</param>
        /// <param name="metadata">Data associated with the component.</param>
        /// <param name="target">The component registration upon which this registration is based.</param>
        /// <param name="options">Registration options.</param>
        public ComponentRegistration(
            Guid id,
            IInstanceActivator activator,
            IComponentLifetime lifetime,
            InstanceSharing sharing,
            InstanceOwnership ownership,
            IResolvePipelineBuilder pipelineBuilder,
            IEnumerable <Service> services,
            IDictionary <string, object?> metadata,
            IComponentRegistration target,
            RegistrationOptions options = RegistrationOptions.None)
            : this(id, activator, lifetime, sharing, ownership, pipelineBuilder, services, metadata, options)
        {
            _target = target ?? throw new ArgumentNullException(nameof(target));

            // Certain flags carry over from the target.
            Options = options | (_target.Options & OptionsCopiedFromTargetRegistration);
        }
Пример #8
0
        /// <summary>
        /// Create a new component registration.
        /// </summary>
        /// <param name="id">Unique identifier for the component.</param>
        /// <param name="activator">Activator used to activate instances.</param>
        /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
        /// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
        /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
        /// <param name="services">Services the component provides.</param>
        /// <param name="metadata">Data associated with the component.</param>
        /// <param name="target">The component registration upon which this registration is based.</param>
        public ComponentRegistration(
            Guid id,
            IInstanceActivator activator,
            IComponentLifetime lifetime,
            InstanceSharing sharing,
            InstanceOwnership ownership,
            IEnumerable <Service> services,
            IDictionary <string, object> metadata,
            IComponentRegistration target)
            : this(id, activator, lifetime, sharing, ownership, services, metadata)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            _target = target;
        }
Пример #9
0
 /// <summary>
 /// Create a new component registration.
 /// </summary>
 /// <param name="id">Unique identifier for the component.</param>
 /// <param name="activator">Activator used to activate instances.</param>
 /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
 /// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
 /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
 /// <param name="services">Services the component provides.</param>
 /// <param name="metadata">Data associated with the component.</param>
 public ComponentRegistration(
     Guid id,
     IInstanceActivator activator,
     IComponentLifetime lifetime,
     InstanceSharing sharing,
     InstanceOwnership ownership,
     IEnumerable<Service> services,
     IDictionary<string, object> metadata)
 {
     Id = id;
     Activator = Enforce.ArgumentNotNull(activator, "activator");
     Lifetime = Enforce.ArgumentNotNull(lifetime, "lifetime");
     Sharing = sharing;
     Ownership = ownership;
     Services = Enforce.ArgumentElementNotNull(
         Enforce.ArgumentNotNull(services, "services"), "services").ToList();
     Metadata = new Dictionary<string, object>(
         Enforce.ArgumentNotNull(metadata, "metadata"));
 }
Пример #10
0
 /// <summary>
 /// Create a new component registration.
 /// </summary>
 /// <param name="id">Unique identifier for the component.</param>
 /// <param name="activator">Activator used to activate instances.</param>
 /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
 /// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
 /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
 /// <param name="services">Services the component provides.</param>
 /// <param name="metadata">Data associated with the component.</param>
 public ComponentRegistration(
     Guid id,
     IInstanceActivator activator,
     IComponentLifetime lifetime,
     InstanceSharing sharing,
     InstanceOwnership ownership,
     IEnumerable <Service> services,
     IDictionary <string, object> metadata)
 {
     Id        = id;
     Activator = Enforce.ArgumentNotNull(activator, "activator");
     Lifetime  = Enforce.ArgumentNotNull(lifetime, "lifetime");
     Sharing   = sharing;
     Ownership = ownership;
     Services  = Enforce.ArgumentElementNotNull(
         Enforce.ArgumentNotNull(services, "services"), "services").ToList();
     Metadata = new Dictionary <string, object>(
         Enforce.ArgumentNotNull(metadata, "metadata"));
 }
Пример #11
0
 /// <summary>
 /// Create a new component registration.
 /// </summary>
 /// <param name="id">Unique identifier for the component.</param>
 /// <param name="activator">Activator used to activate instances.</param>
 /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
 /// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
 /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
 /// <param name="services">Services the component provides.</param>
 /// <param name="metadata">Data associated with the component.</param>
 public ComponentRegistration(
     Guid id,
     IInstanceActivator activator,
     IComponentLifetime lifetime,
     InstanceSharing sharing,
     InstanceOwnership ownership,
     IEnumerable <Service> services,
     IDictionary <string, object> metadata)
 {
     Id        = id;
     Activator = activator;          // Enforce.ArgumentNotNull(activator, "activator");
     Lifetime  = lifetime;           // Enforce.ArgumentNotNull(lifetime, "lifetime");
     Sharing   = sharing;
     Ownership = ownership;
     //var list = new List<Service>(services);
     //if (list.Contains(null))
     //Enforce.ArgumentElementNotNull(services, "services");
     Services = services;
     Metadata = metadata;            //new Dictionary<string, object>(Enforce.ArgumentNotNull(metadata, "metadata"));
 }
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="activator"></param>
 /// <param name="lifetime"></param>
 /// <param name="sharing"></param>
 /// <param name="ownership"></param>
 /// <param name="services"></param>
 /// <param name="metadata"></param>
 /// <param name="serviceDescriptor"></param>
 public ServiceDescriptorComponentRegistration(
     Guid id,
     IInstanceActivator activator,
     IComponentLifetime lifetime,
     InstanceSharing sharing,
     InstanceOwnership ownership,
     IEnumerable <Service> services,
     IDictionary <string, object> metadata,
     ServiceDescriptor serviceDescriptor) :
     base(
         id,
         activator,
         lifetime,
         sharing,
         ownership,
         services,
         metadata)
 {
     this.serviceDescriptor = serviceDescriptor ?? throw new ArgumentNullException(nameof(serviceDescriptor));
 }
Пример #13
0
		/// <summary>
		/// Create a new component registration.
		/// </summary>
		/// <param name="id">Unique identifier for the component.</param>
		/// <param name="activator">Activator used to activate instances.</param>
		/// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
		/// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
		/// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
		/// <param name="services">Services the component provides.</param>
		/// <param name="metadata">Data associated with the component.</param>
		public ComponentRegistration(
			Guid id,
			IInstanceActivator activator,
			IComponentLifetime lifetime,
			InstanceSharing sharing,
			InstanceOwnership ownership,
			IEnumerable<Service> services,
			IDictionary<string, object> metadata)
		{
			Id = id;
			Activator = activator;// Enforce.ArgumentNotNull(activator, "activator");
			Lifetime = lifetime;// Enforce.ArgumentNotNull(lifetime, "lifetime");
			Sharing = sharing;
			Ownership = ownership;
			//var list = new List<Service>(services);
			//if (list.Contains(null))
			//Enforce.ArgumentElementNotNull(services, "services");
			Services = services;
			Metadata = metadata;//new Dictionary<string, object>(Enforce.ArgumentNotNull(metadata, "metadata"));
		}
Пример #14
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="System.Object" />
 ///     class.
 /// </summary>
 // ReSharper disable once UnusedMember.Global
 public ComponentRegistration(
     Guid id
     , IInstanceActivator activator
     , IComponentLifetime lifetime
     , InstanceSharing sharing
     , InstanceOwnership ownership
     , IEnumerable <Service> services
     , IDictionary <string, object> metadata
     , IComponentRegistration target
     )
 {
     Id        = id;
     Activator = activator;
     Lifetime  = lifetime;
     Sharing   = sharing;
     Ownership = ownership;
     Services  = services;
     Metadata  = metadata;
     Target    = target;
 }
Пример #15
0
        /// <summary>
        /// Create a new component registration.
        /// </summary>
        /// <param name="id">Unique identifier for the component.</param>
        /// <param name="activator">Activator used to activate instances.</param>
        /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
        /// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
        /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
        /// <param name="services">Services the component provides.</param>
        /// <param name="metadata">Data associated with the component.</param>
        public ComponentRegistration(
            Guid id,
            IInstanceActivator activator,
            IComponentLifetime lifetime,
            InstanceSharing sharing,
            InstanceOwnership ownership,
            IEnumerable<Service> services,
            IDictionary<string, object> metadata)
        {
            if (activator == null) throw new ArgumentNullException(nameof(activator));
            if (lifetime == null) throw new ArgumentNullException(nameof(lifetime));
            if (services == null) throw new ArgumentNullException(nameof(services));
            if (metadata == null) throw new ArgumentNullException(nameof(metadata));

            Id = id;
            Activator = activator;
            Lifetime = lifetime;
            Sharing = sharing;
            Ownership = ownership;
            Services = Enforce.ArgumentElementNotNull(services, nameof(services)).ToList();
            Metadata = new Dictionary<string, object>(metadata);
        }
Пример #16
0
        /// <summary>
        /// Create a new component registration.
        /// </summary>
        /// <param name="id">Unique identifier for the component.</param>
        /// <param name="activator">Activator used to activate instances.</param>
        /// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
        /// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
        /// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
        /// <param name="services">Services the component provides.</param>
        /// <param name="metadata">Data associated with the component.</param>
        /// <param name="target">The component registration upon which this registration is based.</param>
        public ComponentRegistration(
            Guid id,
            IInstanceActivator activator,
            IComponentLifetime lifetime,
            InstanceSharing sharing,
            InstanceOwnership ownership,
            IEnumerable<Service> services,
            IDictionary<string, object> metadata,
            IComponentRegistration target)
            : this(id, activator, lifetime, sharing, ownership, services, metadata)
        {
            if (target == null) throw new ArgumentNullException(nameof(target));

            _target = target;
        }
Пример #17
0
 public ExternalComponentRegistration(Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable <Service> services, IDictionary <string, object?> metadata, IComponentRegistration target, bool isAdapterForIndividualComponent)
     : base(id, activator, lifetime, sharing, ownership, services, metadata, target, isAdapterForIndividualComponent)
 {
 }
Пример #18
0
 public OwnershipModel GetOwnershipModel(InstanceOwnership ownership)
 {
     return((OwnershipModel)(int)ownership);
 }
Пример #19
0
        internal static void AssertOwnership <TComponent>(this IComponentContext context, InstanceOwnership ownership)
        {
            var registration = context.RegistrationFor <TComponent>();

            Assert.Equal(ownership, registration.Ownership);
        }
Пример #20
0
 public ComponentRegistration(Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable <Service> services, IDictionary <string, object> metadata)
 {
     this.Id        = id;
     this.Activator = Enforce.ArgumentNotNull <IInstanceActivator>(activator, "activator");
     this.Lifetime  = Enforce.ArgumentNotNull <IComponentLifetime>(lifetime, "lifetime");
     this.Sharing   = sharing;
     this.Ownership = ownership;
     this.Services  = Enforce.ArgumentElementNotNull <IEnumerable <Service> >(Enforce.ArgumentNotNull <IEnumerable <Service> >(services, "services"), "services").ToList <Service>();
     this.Metadata  = new Dictionary <string, object>(Enforce.ArgumentNotNull <IDictionary <string, object> >(metadata, "metadata"));
 }
Пример #21
0
        public static void AssertOwnership <TComponent>(this IComponentContext context, InstanceOwnership ownership)
        {
            var cr = context.RegistrationFor <TComponent>();

            Assert.Equal(ownership, cr.Ownership);
        }
Пример #22
0
		/// <summary>
		/// Create a new component registration.
		/// </summary>
		/// <param name="id">Unique identifier for the component.</param>
		/// <param name="activator">Activator used to activate instances.</param>
		/// <param name="lifetime">Determines how the component will be associated with its lifetime.</param>
		/// <param name="sharing">Whether the component is shared within its lifetime scope.</param>
		/// <param name="ownership">Whether the component instances are disposed at the end of their lifetimes.</param>
		/// <param name="services">Services the component provides.</param>
		/// <param name="metadata">Data associated with the component.</param>
		/// <param name="target">The component registration upon which this registration is based.</param>
		public ComponentRegistration(
			Guid id,
			IInstanceActivator activator,
			IComponentLifetime lifetime,
			InstanceSharing sharing,
			InstanceOwnership ownership,
			IEnumerable<Service> services,
			IDictionary<string, object> metadata,
			IComponentRegistration target)
			: this(id, activator, lifetime, sharing, ownership, services, metadata)
		{
			_target = target;// Enforce.ArgumentNotNull(target, "target");
		}
 /// <summary>
 ///   Asserts the current service type has been registered using the specified <see cref="InstanceOwnership"/> on the current <see cref="IContainer"/>.
 /// </summary>
 /// <param name="ownership">The instance ownership mode</param>
 public RegistrationAssertions Owned(InstanceOwnership ownership)
 {
     _registration.Ownership.Should().Be(ownership, $"Type '{Type}' should be owned '{ownership}'");
     return(this);
 }
Пример #24
0
 public OwnershipModel GetOwnershipModel(InstanceOwnership ownership)
 {
     return (OwnershipModel) (int) ownership;
 }