Options for serving JavaScript files transformed via Babel.
예제 #1
0
        /// <summary>
        /// Initialises ReactJS.NET for this application
        /// </summary>
        /// <param name="app">ASP.NET application builder</param>
        /// <param name="configure">ReactJS.NET configuration</param>
        /// <param name="fileOptions">Options to use for serving files</param>
        /// <returns>The application builder (for chaining)</returns>
        public static IApplicationBuilder UseReact(
            this IApplicationBuilder app,
            Action <IReactSiteConfiguration> configure,
            BabelFileOptions fileOptions = null
            )
        {
            EnsureServicesRegistered(app);

            RegisterAspNetServices(React.AssemblyRegistration.Container, app.ApplicationServices);

            Initializer.Initialize(registerOptions => AsPerRequestSingleton(
                                       app.ApplicationServices.GetService <IHttpContextAccessor>(),
                                       registerOptions
                                       ));

            // Camelcase JSON properties by default - Can be overridden per-site in "configure".
            ReactSiteConfiguration.Configuration.JsonSerializerSettings.ContractResolver =
                new CamelCasePropertyNamesContractResolver();

            configure(ReactSiteConfiguration.Configuration);

            // Allow serving of .jsx files
            app.UseMiddleware <BabelFileMiddleware>(fileOptions ?? new BabelFileOptions());

            return(app);
        }
예제 #2
0
		/// <summary>
		/// Initialises ReactJS.NET for this application
		/// </summary>
		/// <param name="app">ASP.NET application builder</param>
		/// <param name="configure">ReactJS.NET configuration</param>
		/// <param name="fileOptions">Options to use for serving files</param>
		/// <returns>The application builder (for chaining)</returns>
		public static IApplicationBuilder UseReact(
			this IApplicationBuilder app,
			Action<IReactSiteConfiguration> configure,
			BabelFileOptions fileOptions = null
		)
		{
			EnsureServicesRegistered(app);

			RegisterAspNetServices(React.AssemblyRegistration.Container, app.ApplicationServices);

			Initializer.Initialize(registerOptions => AsPerRequestSingleton(
				app.ApplicationServices.GetService<IHttpContextAccessor>(), 
				registerOptions
			));

			// Camelcase JSON properties by default - Can be overridden per-site in "configure".
			ReactSiteConfiguration.Configuration.JsonSerializerSettings.ContractResolver =
				new CamelCasePropertyNamesContractResolver();

			configure(ReactSiteConfiguration.Configuration);

			// Allow serving of .jsx files
			app.UseMiddleware<BabelFileMiddleware>(fileOptions ?? new BabelFileOptions());

			return app;
		}
예제 #3
0
		/// <summary>
		/// Creates a new instance of the BabelFileMiddleware.
		/// </summary>
		/// <param name="next">The next middleware in the pipeline.</param>
		/// <param name="options">The configuration options.</param>
		/// <param name="hostingEnv">The hosting environment.</param>
		/// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
		public BabelFileMiddleware(RequestDelegate next, BabelFileOptions options, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory)
		{
			if (next == null)
				throw new ArgumentNullException("next");

			_next = next;
			_hostingEnv = hostingEnv;
			_loggerFactory = loggerFactory;

			// Default values
			_options = options ?? new BabelFileOptions();
		}
예제 #4
0
        /// <summary>
        /// Creates a new instance of the BabelFileMiddleware.
        /// </summary>
        /// <param name="next">The next middleware in the pipeline.</param>
        /// <param name="options">The configuration options.</param>
        /// <param name="hostingEnv">The hosting environment.</param>
        /// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
        public BabelFileMiddleware(RequestDelegate next, BabelFileOptions options, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory)
        {
            if (next == null)
            {
                throw new ArgumentNullException("next");
            }

            _next          = next;
            _hostingEnv    = hostingEnv;
            _loggerFactory = loggerFactory;

            // Default values
            _options = options ?? new BabelFileOptions();
        }
        /// <summary>
        /// Initialises ReactJS.NET for this application
        /// </summary>
        /// <param name="app">ASP.NET application builder</param>
        /// <param name="configure">ReactJS.NET configuration</param>
        /// <param name="fileOptions">Options to use for serving files</param>
        /// <returns>The application builder (for chaining)</returns>
        public static IApplicationBuilder UseReact(
            this IApplicationBuilder app,
            Action<IReactSiteConfiguration> configure,
            BabelFileOptions fileOptions = null
        )
        {
            EnsureServicesRegistered(app);

            React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService<IHostingEnvironment>());
            React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService<IMemoryCache>());
            Initializer.Initialize(registerOptions => AsPerRequestSingleton(
                app.ApplicationServices.GetService<IHttpContextAccessor>(),
                registerOptions
            ));
            configure(ReactSiteConfiguration.Configuration);

            // Allow serving of .jsx files
            app.UseMiddleware<BabelFileMiddleware>(fileOptions ?? new BabelFileOptions());

            return app;
        }
예제 #6
0
        /// <summary>
        /// Initialises ReactJS.NET for this application
        /// </summary>
        /// <param name="app">ASP.NET application builder</param>
        /// <param name="configure">ReactJS.NET configuration</param>
        /// <param name="fileOptions">Options to use for serving files</param>
        /// <returns>The application builder (for chaining)</returns>
        public static IApplicationBuilder UseReact(
            this IApplicationBuilder app,
            Action <IReactSiteConfiguration> configure,
            BabelFileOptions fileOptions = null
            )
        {
            EnsureServicesRegistered(app);

            React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService <IHostingEnvironment>());

            Initializer.Initialize(registerOptions => AsPerRequestSingleton(
                                       app.ApplicationServices.GetService <IHttpContextAccessor>(),
                                       registerOptions
                                       ));
            configure(ReactSiteConfiguration.Configuration);

            // Allow serving of .jsx files
            app.UseMiddleware <BabelFileMiddleware>(fileOptions ?? new BabelFileOptions());

            return(app);
        }
예제 #7
0
        /// <summary>
        /// Initialises ReactJS.NET for this application
        /// </summary>
        /// <param name="app">ASP.NET application builder</param>
        /// <param name="configure">ReactJS.NET configuration</param>
        /// <param name="fileOptions">Options to use for serving files</param>
        /// <returns>The application builder (for chaining)</returns>
        public static IApplicationBuilder UseReact(
            this IApplicationBuilder app,
            Action <IReactSiteConfiguration> configure,
            BabelFileOptions fileOptions = null
            )
        {
            EnsureServicesRegistered(app);

            // Register IApplicationEnvironment in our dependency injection container
            // Ideally this would be in AddReact(IServiceCollection) but we can't
            // access IApplicationEnvironment there.
            React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService <IApplicationEnvironment>());
            React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService <IHostingEnvironment>());

            Initializer.Initialize(registerOptions => AsPerRequestSingleton(app.ApplicationServices, registerOptions));
            configure(ReactSiteConfiguration.Configuration);

            // Allow serving of .jsx files
            app.UseMiddleware <BabelFileMiddleware>(fileOptions ?? new BabelFileOptions());

            return(app);
        }
예제 #8
0
		/// <summary>
		/// Initialises ReactJS.NET for this application
		/// </summary>
		/// <param name="app">ASP.NET application builder</param>
		/// <param name="configure">ReactJS.NET configuration</param>
		/// <param name="fileOptions">Options to use for serving files</param>
		/// <returns>The application builder (for chaining)</returns>
		public static IApplicationBuilder UseReact(
			this IApplicationBuilder app,
			Action<IReactSiteConfiguration> configure,
			BabelFileOptions fileOptions = null
		)
		{
			EnsureServicesRegistered(app);

			// Register IApplicationEnvironment in our dependency injection container
			// Ideally this would be in AddReact(IServiceCollection) but we can't 
			// access IApplicationEnvironment there.
			React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService<IApplicationEnvironment>());
			React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService<IHostingEnvironment>());

			Initializer.Initialize(registerOptions => AsPerRequestSingleton(app.ApplicationServices, registerOptions));
			configure(ReactSiteConfiguration.Configuration);

			// Allow serving of .jsx files
			app.UseMiddleware<BabelFileMiddleware>(fileOptions ?? new BabelFileOptions());

			return app;
		}