Add `IHtmlGenerator` to DI and enable MVC tag helpers in TagHelperSample.Web

- also fix a couple of minor issues in TagHelperSample.Web
This commit is contained in:
Doug Bunting 2014-10-13 21:46:23 -07:00
parent 339c63d143
commit eb7c82d7c2
6 changed files with 42 additions and 32 deletions

View File

@ -8,7 +8,7 @@ namespace TagHelperSample.Web
{
public void Configure(IApplicationBuilder app)
{
app.UseServices(services => services.AddMvc());
app.UsePerRequestServices(services => services.AddMvc());
app.UseMvc();
}
}

View File

@ -1,6 +1,7 @@

@using TagHelperSample.Web.Models
@model User
@addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"
<h2>Create</h2>

View File

@ -1,6 +1,7 @@

@using TagHelperSample.Web.Models
@model User
@addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"
<h2>Edit</h2>

View File

@ -1,6 +1,7 @@

@using TagHelperSample.Web.Models
@model IEnumerable<User>
@addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"
<h2>Index</h2>
<p>
@ -10,26 +11,28 @@
@if (Model != null && Model.Count() != 0)
{
<div class="form-horizontal">
@foreach (var item in Model)
@for (var index = 0; index < Model.Count(); ++index)
{
@*
<div class="form-group">
<label for="@item.Name" />
<input type="text" for="@item.Name" disabled="disabled" readonly="readonly" />
<label for="[index].Name" />
<input type="text" for="[index].Name" disabled="disabled" readonly="readonly" />
</div>
<div class="form-group">
<label for="@item.DateOfBirth" />
<input type="date" for="@item.DateOfBirth" disabled="disabled" readonly="readonly" />
<label for="[index].DateOfBirth" />
<input type="date" for="[index].DateOfBirth" disabled="disabled" readonly="readonly" />
</div>
<div class="form-group">
<label for="@item.YearsEmployeed" />
<input type="number" for="@item.YearsEmployeed" disabled="disabled" readonly="readonly" />
<label for="[index].YearsEmployeed" />
<input type="number" for="[index].YearsEmployeed" disabled="disabled" readonly="readonly" />
</div>
<div class="form-group">
<label for="@item.Blurb" />
<textarea rows="4" for="@item.Blurb" disabled="disabled" readonly="readonly" />
<label for="[index].Blurb" />
<textarea rows="4" for="[index].Blurb" disabled="disabled" readonly="readonly" />
</div>
<a action="Edit" controller="Home" route="MyRouteName" route-id="@item.Id">Edit</a>
<a action="Edit" controller="Home" route="MyRouteName" route-id="[index].Id">Edit</a>
*@
}
</div>
}

View File

@ -1,24 +1,25 @@
{
"compilationOptions": {
"warningsAsErrors": true
"compilationOptions": {
"warningsAsErrors": true
},
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.Framework.ConfigurationModel": "1.0.0-*",
"Microsoft.AspNet.Mvc.TagHelpers": ""
},
"commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001"
},
"frameworks": {
"aspnet50": {
"dependencies": {
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*"
}
},
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.Framework.ConfigurationModel": "1.0.0-*"
},
"commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001"
},
"frameworks": {
"aspnet50": {
"dependencies": {
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*"
}
},
"aspnetcore50": {
"dependencies": { }
}
"aspnetcore50": {
"dependencies": {}
}
}
}
}

View File

@ -138,6 +138,10 @@ namespace Microsoft.AspNet.Mvc
// Only want one ITagHelperActivator so it can cache Type activation information. Types won't conflict.
yield return describe.Singleton<ITagHelperActivator, DefaultTagHelperActivator>();
// DefaultHtmlGenerator is pretty much stateless but depends on Scoped services such as IUrlHelper and
// IActionBindingContextProvider. Therefore it too is scoped.
yield return describe.Transient<IHtmlGenerator, DefaultHtmlGenerator>();
yield return describe.Transient<IViewComponentSelector, DefaultViewComponentSelector>();
yield return describe.Singleton<IViewComponentActivator, DefaultViewComponentActivator>();
yield return describe.Transient<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>();