Пример #1
0
        /// <summary>
        /// Create an <see cref="INodeServices"/> instance according to the supplied options.
        /// </summary>
        /// <param name="options">Options for creating the <see cref="INodeServices"/> instance.</param>
        /// <returns>An <see cref="INodeServices"/> instance.</returns>
        public static INodeServices CreateNodeServices(NodeServicesOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(new NodeServicesImpl(options.NodeInstanceFactory));
        }
        public NodeServicesTest()
        {
            // In typical ASP.NET Core applications, INodeServices is made available
            // through DI using services.AddNodeServices(). But for these tests we
            // create our own INodeServices instance manually, since the tests are
            // not about DI (and we might want different config for each test).
            var serviceProvider = new ServiceCollection().BuildServiceProvider();
            var options         = new NodeServicesOptions(serviceProvider);

            _nodeServices = NodeServicesFactory.CreateNodeServices(options);
        }
Пример #3
0
        public static INodeServices CreateNodeServices(NodeServicesOptions options)
        {
            var watchFileExtensions = options.WatchFileExtensions ?? DefaultWatchFileExtensions;

            switch (options.HostingModel)
            {
            case NodeHostingModel.Http:
                return(new HttpNodeInstance(options.ProjectPath, /* port */ 0, watchFileExtensions));

            case NodeHostingModel.Socket:
                return(new SocketNodeInstance(options.ProjectPath, watchFileExtensions));

            default:
                throw new ArgumentException("Unknown hosting model: " + options.HostingModel);
            }
        }
Пример #4
0
        public static INodeServices CreateNodeServices(NodeServicesOptions options)
        {
            var watchFileExtensions = options.WatchFileExtensions ?? defaultWatchFileExtensions;

            switch (options.HostingModel)
            {
            case NodeHostingModel.Http:
                return(new HttpNodeInstance(options.ProjectPath, /* port */ 0, watchFileExtensions));

            case NodeHostingModel.InputOutputStream:
                return(new InputOutputStreamNodeInstance(options.ProjectPath));

            default:
                throw new System.ArgumentException("Unknown hosting model: " + options.HostingModel.ToString());
            }
        }
Пример #5
0
        public static void AddNodeServices(this IServiceCollection serviceCollection, NodeServicesOptions options)
        {
            serviceCollection.AddSingleton(typeof(INodeServices), serviceProvider =>
            {
                var hostEnv = serviceProvider.GetRequiredService <IHostingEnvironment>();
                if (string.IsNullOrEmpty(options.ProjectPath))
                {
                    options.ProjectPath = hostEnv.ContentRootPath;
                }

                return(CreateNodeServices(options));
            });
        }