using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging;
namespace netcore_mvc { public classProgram { public static void Main(string[] args) { BuildWebHost(args).Run(); }
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options;
// This method gets calledby the runtime. Use this methodtoadd services to the container. publicvoid ConfigureServices(IServiceCollection services) { services.AddMvcCore(); }
// This method gets calledby the runtime. Use this methodto configure the HTTP request pipeline. publicvoid Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseMvc(); } } }
usingSystem; usingSystem.Collections.Generic; usingSystem.Diagnostics; usingSystem.Linq; usingSystem.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using netcore_mvc_templates.Models;
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging;
namespace netcore_mvc_templates { public classProgram { public static void Main(string[] args) { BuildWebHost(args).Run(); }
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection;
// This method gets calledby the runtime. Use this methodtoadd services to the container. publicvoid ConfigureServices(IServiceCollection services) { /* An unhandled exception was thrown by the application. System.InvalidOperationException: No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has been registered. Solution: Use AddMvc() instead of AddMvcCore() in Startup.cs and it will work. */ // services.AddMvcCore(); services.AddMvc(); }
// This method gets calledby the runtime. Use this methodto configure the HTTP request pipeline. publicvoid Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseStaticFiles();
These files are quite long to be shown in this article but you can view them at: https://github.com/kataras/iris/tree/master/_benchmarks/netcore-mvc-templates
const ( // templatesDir is the exactly the same path that .NET Core is using for its templates, // in order to reduce the size in the repository. // Change the "C\\mygopath" to your own GOPATH. templatesDir = "C:\\mygopath\\src\\github.com\\kataras\\iris\\_benchmarks\\netcore-mvc-templates\\wwwroot" )
/* ../netcore-mvc-templates/wwwroot/css ../netcore-mvc-templates/wwwroot/images ../netcore-mvc-templates/wwwroot/js ../netcore-mvc-templates/wwwroot/lib ../netcore-mvc-templates/wwwroot/favicon.ico views/shared/layout.html views/shared/error.html views/about.html views/contact.html views/index.html These files are quite long to be shown in this article but you can view them at: https://github.com/kataras/iris/tree/master/_benchmarks/iris-mvc-templates */
运行 Go 服务项目:
1 2 3 4 5 6
$ cd iris-mvc-templates $ go run main.go Now listening on: http://localhost:5000 Application started. Press CTRL+C to shut down.