.NET Core MVC Linux Sample

From no name for this wiki
Revision as of 09:32, 17 September 2016 by Claude (talk | contribs) (MyController.json)
Jump to: navigation, search

project.json

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        },
        "Microsoft.AspNetCore.Razor.Tools": {
          "version": "1.0.0-preview2-final", 
          "type": "build"
        },
        "Microsoft.AspNetCore.Mvc": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
        "Microsoft.Extensions.Logging": "1.0.0",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.Extensions.Logging.Debug": "1.0.0",
        "Microsoft.Extensions.Configuration.Json": "1.0.0",
        "Microsoft.AspNetCore.Diagnostics": "1.0.0",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
        "Microsoft.AspNetCore.StaticFiles": "1.0.0"
      },
      "imports": "dnxcore50",
      "frameworkAssemblies": {
        
      }
    }
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  }
  
}

Programm.cs

using Microsoft.AspNetCore.Hosting;

namespace aspnetcoreapp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(System.IO.Directory.GetCurrentDirectory())
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
    }
}

MyController.cs

using Microsoft.AspNetCore.Mvc;

namespace aspnetcoreapp
{
    public class MapController : Controller {

        IOsmService _osmService;

        public MapController(IOsmService osmService){
            _osmService = osmService;
        }
        
        public string GetString() {
            return "Hello World from Controller!";
        }

        public ActionResult MyView()
        {
            MapInfo model = _osmService.LoadCoordinates();
            
            return View("MyView", model);
        }
    }
}

Model

View