Switch to using DI to acquire Node instances. Bump versions to alpha2.

This commit is contained in:
SteveSandersonMS
2015-11-02 13:35:14 -08:00
parent 301657a207
commit de991b9858
23 changed files with 103 additions and 92 deletions

View File

@@ -5,7 +5,7 @@ namespace ES2015Example.Controllers
{
public class HomeController : Controller
{
public async Task<IActionResult> Index(int pageIndex)
public IActionResult Index(int pageIndex)
{
return View();
}

View File

@@ -6,13 +6,17 @@ namespace ES2015Example.Controllers
{
public class ScriptController : Controller
{
private static NodeInstance nodeInstance = new NodeInstance();
private INodeServices nodeServices;
public ScriptController(INodeServices nodeServices) {
this.nodeServices = nodeServices;
}
public async Task<ContentResult> Transpile(string filename)
{
// TODO: Don't hard-code wwwroot; use proper path conversions
var fileContents = System.IO.File.ReadAllText("wwwroot/" + filename);
var transpiledResult = await nodeInstance.Invoke("transpilation.js", fileContents, Request.Path.Value);
var transpiledResult = await this.nodeServices.Invoke("transpilation.js", fileContents, Request.Path.Value);
return Content(transpiledResult, "application/javascript");
}
}

View File

@@ -5,6 +5,7 @@ using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using Microsoft.AspNet.NodeServices;
namespace ES2015Example
{
@@ -27,6 +28,9 @@ namespace ES2015Example
{
// Add MVC services to the services container.
services.AddMvc();
// Enable Node Services
services.AddNodeServices();
}
// Configure is called after ConfigureServices is called.

View File

@@ -16,7 +16,7 @@
"Microsoft.Framework.Logging": "1.0.0-beta8",
"Microsoft.Framework.Logging.Console": "1.0.0-beta8",
"Microsoft.Framework.Logging.Debug": "1.0.0-beta8",
"Microsoft.AspNet.NodeServices": "1.0.0-alpha1"
"Microsoft.AspNet.NodeServices": "1.0.0-alpha2"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"