/// <summary>
 /// Registers the <see cref="IHttpContextAccessor"/> to be used as the access for the
 /// <see cref="HttpContext"/>.
 /// By default the controller extension methods to create the sources use the
 /// <see cref="HttpContext"/> provided by the controller.
 /// This is only necessary if you want to use pipes that require the
 ///  <see cref="HttpContext"/> and want to create sources without a controller.
 /// </summary>
 /// <remarks>
 /// The ASP.NET Core Identity package registers <see cref="IHttpContextAccessor"/>.
 /// </remarks>
 /// <param name="builder">The FluentRestBuilder configuration instance.</param>
 /// <returns>The provided FluentRestBuilder configuration instance.</returns>
 public static IFluentRestBuilderConfiguration UseHttpContextAccessor(
     this IFluentRestBuilderConfiguration builder)
 {
     builder.Services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     builder.Services.AddScoped <IScopedStorage <HttpContext>, HttpContextStorage>();
     return(builder);
 }
Beispiel #2
0
 /// <summary>
 /// Registers the <see cref="IActionContextAccessor"/> to be used to create an instance
 /// of <see cref="IUrlHelper"/>.
 /// By default the controller extension methods to create the observables use the
 /// <see cref="IUrlHelper"/> provided by the controller.
 /// This is only necessary if you want to use operators that require the
 /// <see cref="IUrlHelper"/> and want to create observables without a controller.
 /// </summary>
 /// <param name="builder">The FluentRestBuilder configuration instance.</param>
 /// <returns>The provided FluentRestBuilder configuration instance.</returns>
 public static IFluentRestBuilderConfiguration UseActionContextAccessorForUrlHelper(
     this IFluentRestBuilderConfiguration builder)
 {
     builder.Services.TryAddSingleton <IActionContextAccessor, ActionContextAccessor>();
     builder.Services.AddScoped <IScopedStorage <IUrlHelper>, UrlHelperStorage>();
     return(builder);
 }
 /// <summary>
 /// Register the Entity Framework Core related pipes.
 /// </summary>
 /// <typeparam name="TContext">The database context.</typeparam>
 /// <param name="builder">The FluentRestBuilder configuration instance.</param>
 /// <returns>The given FluentRestBuilder configuration instance.</returns>
 public static IFluentRestBuilderConfiguration AddEntityFrameworkCoreIntegration <TContext>(
     this IFluentRestBuilderConfiguration builder)
     where TContext : DbContext
 {
     builder.Services
     .TryAddScoped <IScopedStorage <DbContext>, DbContextScopedStorage <TContext> >();
     return(builder);
 }
 /// <summary>
 /// Configures filters and order by expressions for all non-complex properties
 /// of an entity.
 /// <para>
 /// Allows <see cref="ApplyFilterByClientRequestOperator"/> and
 /// <see cref="ApplyOrderByClientRequestOperator"/> to be used without parameters.
 /// </para>
 /// </summary>
 /// <typeparam name="TEntity">The entity type.</typeparam>
 /// <param name="builder">The FluentRestBuilder configuration instance.</param>
 /// <returns>The provided FluentRestBuilder configuration instance.</returns>
 public static IFluentRestBuilderConfiguration ConfigureFiltersAndOrderByExpressionsForEntity <TEntity>(
     this IFluentRestBuilderConfiguration builder)
 {
     builder.Services.AddSingleton <IOrderByExpressionDictionary <TEntity> >(
         s => new OrderByExpressionDictionary <TEntity>().AddProperties());
     builder.Services.AddSingleton <IFilterExpressionProviderDictionary <TEntity> >(
         s => new FilterExpressionProviderDictionary <TEntity>(s).AddPropertyFilters());
     return(builder);
 }
        /// <summary>
        /// Configures filters and order by expressions for all non-complex properties
        /// of all entities in the given <see cref="DbContext"/>.
        /// <para>
        /// Allows <see cref="ApplyFilterByClientRequestOperator"/> and
        /// <see cref="ApplyOrderByClientRequestOperator"/> to be used without parameters.
        /// </para>
        /// </summary>
        /// <typeparam name="TContext">The <see cref="DbContext"/> type.</typeparam>
        /// <param name="builder">The FluentRestBuilder configuration instance.</param>
        /// <returns>The given FluentRestBuilder configuration instance.</returns>
        public static IFluentRestBuilderConfiguration ConfigureFiltersAndOrderByExpressionsForDbContextEntities <TContext>(
            this IFluentRestBuilderConfiguration builder)
            where TContext : DbContext
        {
            var properties = ResolveDbSetProperties <TContext>();
            var method     = ResolveMethod();

            foreach (var property in properties)
            {
                var entityType = property.PropertyType.GenericTypeArguments
                                 .Single();
                method.MakeGenericMethod(entityType)
                .Invoke(null, new object[] { builder });
            }

            return(builder);
        }