/// <summary>
 /// Emits an <see cref="OptionsResult"/> which lists the allowed
 /// HTTP verbs.
 /// <para>
 /// Catches <see cref="ValidationException"/> and converts it to
 /// an appropriate <see cref="IActionResult"/>.
 /// </para>
 /// <para>Requires usage of <see cref="HttpContextProviderAttribute"/>.</para>
 /// </summary>
 /// <typeparam name="TSource">The type of the value.</typeparam>
 /// <param name="observable">The parent observable.</param>
 /// <param name="factory">A factory function for the allowed HTTP verbs.</param>
 /// <returns>An instance of <see cref="IProviderObservable{IActionResult}"/>.</returns>
 public static IProviderObservable <IActionResult> ToOptionsResult <TSource>(
     this IProviderObservable <TSource> observable,
     Func <AllowedOptionsBuilder <TSource>, AllowedOptionsBuilder <TSource> > factory)
 {
     Check.IsNull(factory, nameof(factory));
     return(observable.ToOptionsResult(s =>
     {
         var httpContext = observable.ServiceProvider
                           .GetRequiredService <IScopedStorage <HttpContext> >();
         var allowedOptionsBuilder = new AllowedOptionsBuilder <TSource>(
             httpContext?.Value.User);
         return factory(allowedOptionsBuilder)
         .GenerateAllowedVerbs(s);
     }));
 }