Make app.AddNodeServices optional in Angular case. Fix tag helper attribute name. Bump versions.

This commit is contained in:
SteveSandersonMS
2015-11-02 20:07:31 -08:00
parent 37eb4efff0
commit 7e1955c6fe
10 changed files with 22 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.NodeServices;
using Microsoft.AspNet.Http.Extensions;
namespace Microsoft.AspNet.NodeServices.Angular
@@ -10,6 +10,7 @@ namespace Microsoft.AspNet.NodeServices.Angular
public class AngularRunAtServerTagHelper : TagHelper
{
static StringAsTempFile nodeScript;
static INodeServices fallbackNodeServices; // Used only if no INodeServices was registered with DI
static AngularRunAtServerTagHelper() {
// Consider populating this lazily
@@ -17,8 +18,8 @@ namespace Microsoft.AspNet.NodeServices.Angular
nodeScript = new StringAsTempFile(script); // Will be cleaned up on process exit
}
const string PrerenderModuleAttributeName = "aspnet-ng2-prerender-module";
const string PrerenderExportAttributeName = "aspnet-ng2-prerender-export";
const string PrerenderModuleAttributeName = "asp-ng2-prerender-module";
const string PrerenderExportAttributeName = "asp-ng2-prerender-export";
[HtmlAttributeName(PrerenderModuleAttributeName)]
public string ModuleName { get; set; }
@@ -29,10 +30,16 @@ namespace Microsoft.AspNet.NodeServices.Angular
private IHttpContextAccessor contextAccessor;
private INodeServices nodeServices;
public AngularRunAtServerTagHelper(INodeServices nodeServices, IHttpContextAccessor contextAccessor)
public AngularRunAtServerTagHelper(IServiceProvider nodeServices, IHttpContextAccessor contextAccessor)
{
this.contextAccessor = contextAccessor;
this.nodeServices = nodeServices;
this.nodeServices = (INodeServices)nodeServices.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
// Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
// in your startup file, but then again it might be confusing that you don't need to.
if (this.nodeServices == null) {
this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http);
}
}
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)