Пример #1
0
        void IExpandableDomain.Initialize(
            DomainConfiguration derivedConfiguration)
        {
            if (this.IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            if (this.domainContext != null)
            {
                throw new InvalidOperationException();
            }

            Ensure.NotNull(derivedConfiguration, "derivedConfiguration");
            var baseConfiguration = this.DomainConfiguration;
            var candidate         = derivedConfiguration;

            while (candidate != baseConfiguration)
            {
                if (candidate.BaseConfiguration == null)
                {
                    // TODO GitHubIssue#24 : error message
                    throw new ArgumentException();
                }

                candidate = candidate.BaseConfiguration;
            }

            this.domainConfiguration = derivedConfiguration;
            this.domainContext       = this.CreateDomainContext(derivedConfiguration);
            DomainParticipantAttribute.ApplyInitialization(
                this.GetType(), this, this.domainContext);
        }
Пример #2
0
        /// <summary>
        /// Performs application-defined tasks associated with
        /// freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (!this.IsDisposed && this.domainContext != null)
            {
                DomainParticipantAttribute.ApplyDisposal(
                    this.GetType(), this, this.domainContext);
            }

            this.Dispose(true);
            GC.SuppressFinalize(this);
        }
        /// <summary>
        /// Applies initialization routines from any domain participant
        /// attributes specified on a domain type to a domain context.
        /// </summary>
        /// <param name="type">
        /// A domain type.
        /// </param>
        /// <param name="instance">
        /// A domain instance, if applicable.
        /// </param>
        /// <param name="context">
        /// A domain context.
        /// </param>
        public static void ApplyInitialization(
            Type type, object instance, DomainContext context)
        {
            Ensure.NotNull(type, "type");
            Ensure.NotNull(context, "context");
            if (type.BaseType != null)
            {
                DomainParticipantAttribute.ApplyInitialization(
                    type.BaseType, instance, context);
            }

            var attributes = type.GetCustomAttributes(
                typeof(DomainParticipantAttribute), false);

            foreach (DomainParticipantAttribute attribute in attributes)
            {
                attribute.Initialize(context, type, instance);
            }
        }
        /// <summary>
        /// Applies disposal routines from any domain participant
        /// attributes specified on a domain type to a domain context.
        /// </summary>
        /// <param name="type">
        /// A domain type.
        /// </param>
        /// <param name="instance">
        /// A domain instance, if applicable.
        /// </param>
        /// <param name="context">
        /// A domain context.
        /// </param>
        public static void ApplyDisposal(
            Type type, object instance, DomainContext context)
        {
            Ensure.NotNull(type, "type");
            Ensure.NotNull(context, "context");
            var attributes = type.GetCustomAttributes(
                typeof(DomainParticipantAttribute), false);

            foreach (DomainParticipantAttribute attribute in attributes.Reverse())
            {
                attribute.Dispose(context, type, instance);
            }

            if (type.BaseType != null)
            {
                DomainParticipantAttribute.ApplyDisposal(
                    type.BaseType, instance, context);
            }
        }
        /// <summary>
        /// Applies configuration from any domain participant attributes
        /// specified on a domain type to a domain configuration.
        /// </summary>
        /// <param name="type">
        /// A domain type.
        /// </param>
        /// <param name="configuration">
        /// A domain configuration.
        /// </param>
        public static void ApplyConfiguration(
            Type type, DomainConfiguration configuration)
        {
            Ensure.NotNull(type, "type");
            Ensure.NotNull(configuration, "configuration");
            if (type.BaseType != null)
            {
                DomainParticipantAttribute.ApplyConfiguration(
                    type.BaseType, configuration);
            }

            var attributes = type.GetCustomAttributes(
                typeof(DomainParticipantAttribute), false);

            foreach (DomainParticipantAttribute attribute in attributes)
            {
                attribute.Configure(configuration, type);
            }
        }