Skip to content
Permalink
Browse files

Converted to .NET Core 1.0

  • Loading branch information...
Nick Soper
Nick Soper committed Aug 24, 2016
1 parent 08a9918 commit b41ad38794c69a70a572be3ffad051fd2d7c53c0
@@ -1,6 +1,6 @@
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-rc1-update1"
"version": "1.0.0-preview2-003121"
}
}
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNetCore.Mvc;
using MvcLibrary.Models;
using Microsoft.Extensions.Logging;

@@ -8,7 +8,7 @@
namespace MvcLibrary.Controllers
{
[Route("api/[controller]")]
public class BooksController : Controller
public class BooksController : ControllerBase
{
private readonly IBookRepository books;
private readonly ILogger logger;
@@ -31,7 +31,7 @@ public IActionResult GetById(string id)
var book = this.books.Find(id);
if (book == null)
{
return this.HttpNotFound();
return this.NotFound();
}

return this.Ok(book);
@@ -42,12 +42,12 @@ public IActionResult Create([FromBody]Book book)
{
if (book == null)
{
return this.HttpBadRequest();
return this.BadRequest();
}

this.books.Add(book);

this.logger.LogVerbose("Added {0} by {1}", book.Title, book.Author);
this.logger.LogTrace("Added {0} by {1}", book.Title, book.Author);

return this.CreatedAtRoute("GetBook", new { id = book.Id }, book);
}
@@ -57,18 +57,18 @@ public IActionResult Update(string id, [FromBody]Book book)
{
if (book.Id != id)
{
return this.HttpBadRequest();
return this.BadRequest();
}

var existingBook = this.books.Find(id);
if (existingBook == null)
{
return this.HttpNotFound();
return this.NotFound();
}

this.books.Update(book);

this.logger.LogVerbose(
this.logger.LogTrace(
"Updated {0} by {1} to {2} by {3}",
existingBook.Title,
existingBook.Author,
@@ -12,7 +12,7 @@ public class BookRepository : IBookRepository
public BookRepository()
{
this.books = new ConcurrentDictionary<string, Book>();
this.Add(new Book { Title = "RESTful API with MVC6", Author = "Nick Soper" });
this.Add(new Book { Title = "RESTful API with ASP.NET Core MVC 1.0", Author = "Nick Soper" });
}

public void Add(Book book)
@@ -9,10 +9,10 @@
<ProjectGuid>a3660ca6-6dec-4848-8ebc-fa31798393af</ProjectGuid>
<RootNamespace>MvcLibrary</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
</Project>
@@ -1,10 +1,10 @@
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MvcLibrary.Models;
using Serilog;
using System.IO;

namespace MvcLibrary
{
@@ -14,6 +14,7 @@ public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json");

this.Configuration = builder.Build();
@@ -33,21 +34,22 @@ public void ConfigureServices(IServiceCollection services)
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
loggerFactory.AddDebug(LogLevel.Verbose);

var log = new Serilog.LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.RollingFile(
pathFormat: env.MapPath("MvcLibrary-{Date}.log"),
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {SourceContext} [{Level}] {Message}{NewLine}{Exception}")
.CreateLogger();

loggerFactory.AddSerilog(log);
loggerFactory.AddDebug(LogLevel.Trace);

app.UseMvc();
}

// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}
@@ -2,7 +2,7 @@
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Verbose",
"Default": "Trace",
"System": "Information",
"Microsoft": "Information"
}
@@ -1,34 +1,25 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"buildOptions": {
"emitEntryPoint": true
},

"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Serilog.Framework.Logging": "1.0.0-rc1-final-10083"
},

"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.Hosting.Server.Abstractions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
}
},

"frameworks": {
"dnx451": { },
"dnxcore50": { }
},

"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
"netcoreapp1.0": {}
}
}

0 comments on commit b41ad38

Please sign in to comment.
You can’t perform that action at this time.