public static IExpressionRouteHelper GetExpressionRouteHelper(this IServiceProvider serviceProvider)
        {
            var expressionRouteHelper = serviceProvider?.GetService<IExpressionRouteHelper>();
            if (expressionRouteHelper == null)
            {
                throw new InvalidOperationException("'AddTypedRouting' must be called after 'AddMvc' in order to use typed routing and link generation.");
            }

            return expressionRouteHelper;
        }
 /// <summary>
 /// Gets an aggregate <see cref="IKeyEscrowSink"/> from the underlying <see cref="IServiceProvider"/>.
 /// This method may return null if no sinks are registered.
 /// </summary>
 public static IKeyEscrowSink GetKeyEscrowSink(this IServiceProvider services)
 {
     var escrowSinks = services?.GetService<IEnumerable<IKeyEscrowSink>>()?.ToList();
     return (escrowSinks != null && escrowSinks.Count > 0) ? new AggregateKeyEscrowSink(escrowSinks) : null;
 }
        public static string GetApplicationUniqueIdentifier(this IServiceProvider services)
        {
            string discriminator = (services?.GetService(typeof(IApplicationDiscriminator)) as IApplicationDiscriminator)?.Discriminator;
#if DNX451 || DNXCORE50 // [[ISSUE1400]] Replace with DNX_ANY when it becomes available
            if (discriminator == null)
            {
                discriminator = (services?.GetService(typeof(IApplicationEnvironment)) as IApplicationEnvironment)?.ApplicationBasePath;
            }
#elif NET451 // do nothing
#else
#error A new target framework was added to project.json, but it's not accounted for in this #ifdef. Please change the #ifdef accordingly.
#endif

            // Remove whitespace and homogenize empty -> null
            discriminator = discriminator?.Trim();
            return (String.IsNullOrEmpty(discriminator)) ? null : discriminator;
        }
 /// <summary>
 /// Retrieves an <see cref="IUrlEncoder"/> from an <see cref="IServiceProvider"/>.
 /// </summary>
 /// <remarks>
 /// This method is guaranteed never to return null.
 /// It will return a default encoder instance if <paramref name="serviceProvider"/> does not contain one or is null.
 /// </remarks>
 public static IUrlEncoder GetUrlEncoder(this IServiceProvider serviceProvider)
 {
     return (IUrlEncoder)serviceProvider?.GetService(typeof(IUrlEncoder)) ?? UrlEncoder.Default;
 }
 /// <summary>
 /// Retrieves an <see cref="IJavaScriptStringEncoder"/> from an <see cref="IServiceProvider"/>.
 /// </summary>
 /// <remarks>
 /// This method is guaranteed never to return null.
 /// It will return a default encoder instance if <paramref name="serviceProvider"/> does not contain one or is null.
 /// </remarks>
 public static IJavaScriptStringEncoder GetJavaScriptStringEncoder(this IServiceProvider serviceProvider)
 {
     return (IJavaScriptStringEncoder)serviceProvider?.GetService(typeof(IJavaScriptStringEncoder)) ?? JavaScriptStringEncoder.Default;
 }
        public static string GetApplicationUniqueIdentifier(this IServiceProvider services)
        {
            string discriminator = (services?.GetService(typeof(IApplicationDiscriminator)) as IApplicationDiscriminator)?.Discriminator;
            if (discriminator == null)
            {
                discriminator = (services?.GetService(typeof(IApplicationEnvironment)) as IApplicationEnvironment)?.ApplicationBasePath;
            }

            // Remove whitespace and homogenize empty -> null
            discriminator = discriminator?.Trim();
            return (String.IsNullOrEmpty(discriminator)) ? null : discriminator;
        }