Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ApiContext" /> class.
        /// </summary>
        /// <param name="provider">
        /// The service provider.
        /// </param>
        /// <param name="configuration">
        /// An API configuration.
        /// </param>
        public ApiContext(IServiceProvider provider, ApiConfiguration configuration)
        {
            Ensure.NotNull(configuration, "configuration");

            this.Configuration = configuration;
            this.serviceProvider = provider;
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ApiContext" /> class.
        /// </summary>
        /// <param name="configuration">
        /// An API configuration.
        /// </param>
        public ApiContext(ApiConfiguration configuration)
        {
            Ensure.NotNull(configuration, "configuration");
            if (!configuration.IsCommitted)
            {
                throw new ArgumentException(Resources.ApiConfigurationShouldBeCommitted);
            }

            this.Configuration = configuration;
        }
Example #3
0
 /// <summary>
 /// Configures an API configuration.
 /// </summary>
 /// <param name="configuration">
 /// An API configuration.
 /// </param>
 /// <param name="type">
 /// The API type on which this attribute was placed.
 /// </param>
 public override void Configure(
     ApiConfiguration configuration,
     Type type)
 {
     var permission = ApiPermission.CreateGrant(
         this.PermissionType,
         this.To,
         this.OnNamespace,
         this.On,
         this.OnChild);
     configuration.AddPermission(permission);
 }
        /// <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);
            }
        }
 /// <summary>
 /// Configures an API configuration.
 /// </summary>
 /// <param name="configuration">
 /// An API configuration.
 /// </param>
 /// <param name="type">
 /// The API type on which this attribute was placed.
 /// </param>
 public override void Configure(
     ApiConfiguration configuration,
     Type type)
 {
     configuration.EnableRoleBasedSecurity();
 }
Example #6
0
        /// <summary>
        /// Enables code-based conventions for an API.
        /// </summary>
        /// <param name="configuration">
        /// An API configuration.
        /// </param>
        /// <param name="targetType">
        /// The type of a class on which code-based conventions are used.
        /// </param>
        /// <remarks>
        /// This method adds hook points to the API configuration that
        /// inspect a target type for a variety of code-based conventions
        /// such as usage of specific attributes or members that follow
        /// certain naming conventions.
        /// </remarks>
        private static void EnableConventions(
            ApiConfiguration configuration,
            Type targetType)
        {
            Ensure.NotNull(configuration, "configuration");
            Ensure.NotNull(targetType, "targetType");

            ConventionBasedChangeSetAuthorizer.ApplyTo(configuration, targetType);
            ConventionBasedChangeSetEntryFilter.ApplyTo(configuration, targetType);
            configuration.AddHookHandler<IChangeSetEntryValidator>(ConventionBasedChangeSetEntryValidator.Instance);
            ConventionBasedApiModelBuilder.ApplyTo(configuration, targetType);
            ConventionBasedOperationProvider.ApplyTo(configuration, targetType);
            ConventionBasedEntitySetFilter.ApplyTo(configuration, targetType);
        }
Example #7
0
 /// <summary>
 /// Creates the API context for this API.
 /// </summary>
 /// <param name="configuration">
 /// The API configuration to use.
 /// </param>
 /// <returns>
 /// The API context for this API.
 /// </returns>
 protected virtual ApiContext CreateApiContext(
     ApiConfiguration configuration)
 {
     return new ApiContext(configuration);
 }
 /// <summary>
 /// Configures an API configuration.
 /// </summary>
 /// <param name="configuration">
 /// An API configuration.
 /// </param>
 /// <param name="type">
 /// The API type on which this attribute was placed.
 /// </param>
 public virtual void Configure(
     ApiConfiguration configuration,
     Type type)
 {
 }
 /// <summary>
 /// Configures an API configuration.
 /// </summary>
 /// <param name="configuration">
 /// An API configuration.
 /// </param>
 /// <param name="type">
 /// The API type on which this attribute was placed.
 /// </param>
 public virtual void Configure(
     ApiConfiguration configuration,
     Type type)
 {
 }
Example #10
0
 /// <summary>
 /// Update an Api configuration after ApiConfiguration is created.
 /// </summary>
 /// <param name="configuration">
 /// An Api configuration.
 /// </param>
 /// <param name="type">
 /// The Api type on which this attribute was placed.
 /// </param>
 public virtual void UpdateApiConfiguration(
     ApiConfiguration configuration,
     Type type)
 {
 }
Example #11
0
 /// <summary>
 /// Creates the API context for this API.
 /// Descendants may further configure the built <see cref="ApiContext"/>.
 /// </summary>
 /// <param name="configuration">
 /// The API configuration to use.
 /// </param>
 /// <returns>
 /// The API context for this API.
 /// </returns>
 protected virtual ApiContext CreateApiContext(
     ApiConfiguration configuration)
 {
     return(new ApiContext(configuration));
 }