Beispiel #1
0
        /// <summary>
        /// Performs application-defined tasks associated with
        /// freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (!this.IsDisposed && this.apiContext != null)
            {
                ApiConfiguratorAttribute.ApplyDisposal(
                    this.GetType(), this, this.apiContext);
            }

            this.Dispose(true);
            GC.SuppressFinalize(this);
        }
        /// <summary>
        /// Applies initialization routines from any API configurator
        /// attributes specified on an API type to an API context.
        /// </summary>
        /// <param name="type">
        /// An API type.
        /// </param>
        /// <param name="instance">
        /// An API instance, if applicable.
        /// </param>
        /// <param name="context">
        /// An API context.
        /// </param>
        public static void ApplyInitialization(
            Type type, object instance, ApiContext context)
        {
            Ensure.NotNull(type, "type");
            Ensure.NotNull(context, "context");
            if (type.BaseType != null)
            {
                ApiConfiguratorAttribute.ApplyInitialization(
                    type.BaseType, instance, context);
            }

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

            foreach (ApiConfiguratorAttribute attribute in attributes)
            {
                attribute.Initialize(context, type, instance);
            }
        }
        /// <summary>
        /// Applies configuration from any API configurator attributes
        /// specified on an API type to an API configuration.
        /// </summary>
        /// <param name="type">
        /// An API type.
        /// </param>
        /// <param name="configuration">
        /// An API configuration.
        /// </param>
        public static void ApplyConfiguration(
            Type type, ApiConfiguration configuration)
        {
            Ensure.NotNull(type, "type");
            Ensure.NotNull(configuration, "configuration");
            if (type.BaseType != null)
            {
                ApiConfiguratorAttribute.ApplyConfiguration(
                    type.BaseType, configuration);
            }

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

            foreach (ApiConfiguratorAttribute attribute in attributes)
            {
                attribute.Configure(configuration, type);
            }
        }
        public static void ApplyApiServices(
            Type type, IServiceCollection services)
        {
            Ensure.NotNull(type, "type");
            Ensure.NotNull(services, "services");
            if (type.BaseType != null)
            {
                ApiConfiguratorAttribute.ApplyApiServices(
                    type.BaseType, services);
            }

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

            foreach (ApiConfiguratorAttribute attribute in attributes)
            {
                attribute.ConfigureApi(services, type);
            }
        }
        /// <summary>
        /// Applies disposal routines from any API configurator
        /// attributes specified on an API type to an API context.
        /// </summary>
        /// <param name="type">
        /// An API type.
        /// </param>
        /// <param name="instance">
        /// An API instance, if applicable.
        /// </param>
        /// <param name="context">
        /// An API context.
        /// </param>
        public static void ApplyDisposal(
            Type type, object instance, ApiContext context)
        {
            Ensure.NotNull(type, "type");
            Ensure.NotNull(context, "context");
            var attributes = type.GetCustomAttributes(
                typeof(ApiConfiguratorAttribute), false);

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

            if (type.BaseType != null)
            {
                ApiConfiguratorAttribute.ApplyDisposal(
                    type.BaseType, instance, context);
            }
        }