mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
Switch to using DI to acquire Node instances. Bump versions to alpha2.
This commit is contained in:
24
Microsoft.AspNet.NodeServices/Configuration.cs
Normal file
24
Microsoft.AspNet.NodeServices/Configuration.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.NodeServices {
|
||||
public static class Configuration {
|
||||
public static void AddNodeServices(this IServiceCollection serviceCollection, NodeHostingModel hostingModel = NodeHostingModel.Http) {
|
||||
serviceCollection.AddSingleton(typeof(INodeServices), (serviceProvider) => {
|
||||
return CreateNodeServices(hostingModel);
|
||||
});
|
||||
}
|
||||
|
||||
private static INodeServices CreateNodeServices(NodeHostingModel hostingModel)
|
||||
{
|
||||
switch (hostingModel)
|
||||
{
|
||||
case NodeHostingModel.Http:
|
||||
return new HttpNodeInstance();
|
||||
case NodeHostingModel.InputOutputStream:
|
||||
return new InputOutputStreamNodeInstance();
|
||||
default:
|
||||
throw new System.ArgumentException("Unknown hosting model: " + hostingModel.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user