Ejemplo n.º 1
0
        /// <summary>
        /// Branches the request pipeline based on the async result of the given predicate.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="predicate">Invoked asynchronously with the request environment to determine if the branch should be taken</param>
        /// <param name="configuration">Configures a branch to take</param>
        /// <returns></returns>
        public static IAppBuilder MapWhenAsync(this IAppBuilder app, PredicateAsync predicate, Action<IAppBuilder> configuration)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            // put middleware in pipeline before creating branch
            var options = new MapWhenOptions { PredicateAsync = predicate };
            IAppBuilder result = app.Use<MapWhenMiddleware>(options);

            // create branch and assign to options
            IAppBuilder branch = app.New();
            configuration(branch);
            options.Branch = (AppFunc)branch.Build(typeof(AppFunc));

            return result;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapWhenMiddleware"/> class
 /// </summary>
 /// <param name="next">The normal application pipeline</param>
 /// <param name="options"></param>
 public MapWhenMiddleware(AppFunc next, MapWhenOptions options)
 {
     if (next == null)
     {
         throw new ArgumentNullException("next");
     }
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     _next    = next;
     _options = options;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapWhenMiddleware"/> class
 /// </summary>
 /// <param name="next">The normal application pipeline</param>
 /// <param name="options"></param>
 public MapWhenMiddleware(OwinMiddleware next, MapWhenOptions options)
     : base(next)
 {
     if (next == null)
     {
         throw new ArgumentNullException("next");
     }
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     _options = options;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapWhenMiddleware"/> class
 /// </summary>
 /// <param name="next">The normal application pipeline</param>
 /// <param name="options"></param>
 public MapWhenMiddleware(AppFunc next, MapWhenOptions options)
 {
     if (next == null)
     {
         throw new ArgumentNullException("next");
     }
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     _next = next;
     _options = options;
 }