.NET Core http://dotnet.github.io/[https://github.com/dotnet/coreclr]
ASP.NET Core 1.0 https://get.asp.net/
Documentation:https://docs.asp.net/en/latest/index.html
MVC:https://docs.asp.net/projects/mvc/en/latest/overview.html
EF: http://docs.efproject.net/en/latest/

WIN下安装VS2015sp1 https://www.visualstudio.com/downloads/download-visual-studio-vs ,安装 AspNet Web Frameworks Tools 2015_KB3137909,也就是 AspNet5,后面会改名 Asp.Net Core 1,DNX会迁移到CLI。

项目结构

相比之前变动比较大的是项目扩展名从csproj变成了xproj,web.config 改名appsetting.json,默认使用了npm与bower等包管理工具,gulp等前端管理工具;使用了DNX 4.5与DNX Core 5.0来支持.NET Framework 与跨平台的.NET Core.

Startup类

public class Startup
{
/// <summary>
/// 配置信息
/// </summary>
public IConfigurationRoot Configuration { get; set; } /// <summary>
/// 程序入口点
/// </summary>
/// <param name="env"></param>
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
} /// <summary>
/// 配置服务
/// </summary>
/// <param name="services"></param>
public void ConfigureServices(IServiceCollection services)
{
services.AddAntiforgery()
.AddCaching()
.AddLogging()
.AddMvc();
/*
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApbContext>(options => options.UseSqlServer(connection));
*/
} /// <summary>
/// 配置组件
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
/// <param name="loggerFactory"></param>
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//使用日志
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
//是否调试模式
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIISPlatformHandler();
//使用静态文件
app.UseStaticFiles();
//使用MVC
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} /// <summary>
/// 配置启动的类
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}

1)Startup方法是整个程序的启动入口,类似于Global.asax,在构造函数中初始化基础配置信息后绑定到一个Configuration属性上。

2)ConfigureServices方法是依赖注入的核心,默认参数services,也可以注册依赖注入自定义的类型,同时需要启一些功能也需要在这里开启,比如添加MVC,缓存,日志模块等 就需要增加如下代码:

services.AddAntiforgery()
.AddCaching()
.AddLogging()
.AddMvc()

在新版的ASP.NET Core 1.0中,除了最基础的模块大部分模块都是以组件化方式来实现,也就是官方的GITHUB上有很多模块源码组成,要启用这些组件首先要添加该模块才能使用。如启用EF模块:

services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApbContext>(options => options.UseSqlServer(connection));

3)Configure方法则是对增加的组件进行配置,如使用MVC功能并配置路由:

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});

ASP.NET Core 1.0 基础与应用启动的更多相关文章

  1. ASP.NET Core 1.0基础之应用启动

    来源https://docs.asp.net/en/latest/fundamentals/startup.html ASP.NET 5 使得应用对每个http请求有完整的控制权.Startup类是程 ...

  2. ASP.NET Core 1.0基础之依赖注入

      来源https://docs.asp.net/en/latest/fundamentals/dependency-injection.html ASP.NET Core 1.0在设计上原生就支持和 ...

  3. ASP.NET Core 1.0 基础之配置

    来源https://docs.asp.net/en/latest/fundamentals/configuration.html ASP.NET Core 1.0支持不同的配置选项.应用配置数据可以是 ...

  4. ASP.NET Core 1.0基础之日志

    过年出去玩了一圈,回来继续翻译.前两天偷懒没有翻译,只是转了两篇C# 7计划中的新features,大家还是很支持的.现在继续完善这个系列. 来源https://docs.asp.net/en/lat ...

  5. ASP.NET Core 1.0基础之诊断

    来源https://docs.asp.net/en/latest/fundamentals/diagnostics.html ASP.NET Core 1.0包含了一些新的特性来辅助诊断问题.可以在S ...

  6. 探索ASP.Net Core 3.0系列四:在ASP.NET Core 3.0的应用中启动时运行异步任务

    前言:在本文中,我将介绍ASP.NET Core 3.0 WebHost的微小更改如何使使用IHostedService在应用程序启动时更轻松地运行异步任务. 翻译 :Andrew Lock   ht ...

  7. ASP.NET Core 1.0基础之静态文件处理

    来源 这些HTML , CSS files, image files, 和JavaScript这些静态文件,是ASP.NET能够直接响应给客户端的.本文详述下ASP.NET和静态文件的关系. Serv ...

  8. 探索ASP.NET Core 3.0系列一:新的项目文件、Program.cs和generic host

    前言:在这篇文章中我们来看看ASP.Net Core 3.0应用程序中一些基本的部分—— .csproj项目文件和Program.cs文件.我将会介绍它们从 ASP.NET Core 2.x 中的默认 ...

  9. [转]探索ASP.NET Core 3.0 系列

    这是该系列的第一篇文章:探索ASP.NET Core 3.0. 第1部分-探索新的项目文件Program.cs和通用主机(本文) 第2部分-比较ASP.NET Core 3.0模板之间的Startup ...

随机推荐

  1. Typecho 独立页面 添加自定义模板

    1.首先在主题文件夹新建一个 ***.php 文件 编写代码 <?php /** * _主题命名 * * @package custom * */$this->need('header.p ...

  2. [转]MySQL源码:Range和Ref优化的成本评估

    MySQL源码:Range和Ref优化的成本评估 原文链接:http://www.orczhou.com/index.php/2012/12/mysql-source-code-optimizer-r ...

  3. java调用执行cmd指令启动weblogic

    这里的例子是启动weblogic import java.io.BufferedReader; import java.io.IOException; import java.io.InputStre ...

  4. 工作总结(二):Web Design

    PHP框架:CakePHP 前端框架:Bootstrap Payment Data Transfer:https://developer.paypal.com/docs/classic/paypal- ...

  5. 关于在Silverlight中添加图片的问题

    在Silverlight中添加图片,目前支持的Image格式有jpg和png两种,如何在目录中添加,有些什么技巧呢? <StackPanel Background="White&quo ...

  6. linux systemctl 常用用法简介

    主要介绍systemctl的几个功能如下: 1.查看某个服务的状态 2.关闭某个服务 3.开启某个服务 4.设置某个为开机自启动 5.关闭某个服务为开机不启动 6.查看所有开启启动的服务 1.查看某个 ...

  7. leaflet入门(二)GeoJson

    GeoJson格式数据的形式 Using GeoJSON with Leaflet GeoJSON is becoming a very popular data format among many ...

  8. 2.1.4synchronized方法与锁对象

    为了证明线程锁的是对象 测试 package com.cky.bean; /** * Created by chenkaiyang on 2017/12/4. */ public class MyOb ...

  9. 2017-11-29 由runnable说起Android中的子线程和主线程

    1.首先纠正一个观点,就是runnable运行在子线程中是错误的观念.runnable只是创建了一个执行任务的对象,但是它本身并不会创建一个新的子线程,Runable只是给你接口让你实现工作线程的工作 ...

  10. Java 时间、字符串

    Date类     类似C#的DateTime类   String类     类似C#的Srting类.大多方法相同,其中valueOF()是C#中实例版本的toString()   StringBu ...