/// <summary>
        /// Adds a default implementation for the <see cref="IHttpContextAccessor"/> service
        /// and configures PHP services.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        /// <returns>The service collection.</returns>
        public static IServiceCollection AddPeachpie(this IServiceCollection services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            ContextExtensions.CurrentContextProvider = () => HttpContextExtension.GetOrCreateContext();

            return(services);
        }
コード例 #2
0
        /// <summary>
        /// Configures PHP services and configuration options.<br/>
        /// Adds <see cref="IHttpContextAccessor"/>.<br/>
        /// Allows current <see cref="Context"/> to be obtained from current ExecutionContext through <see cref="ContextExtensions.CurrentContext"/>.<br/>
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        /// <param name="configureOptions">Delegate configuring the options. Can be <c>null</c>.</param>
        /// <returns>The service collection.</returns>
        public static IServiceCollection AddPhp(this IServiceCollection services, Action <IPhpOptions> configureOptions = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            //
            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            ContextExtensions.CurrentContextProvider = () => HttpContextExtension.GetOrCreateContext();

            ConfigurePhp(services, configureOptions);

            //
            return(services);
        }