.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. ubuntu下非交互式安装MySQL

    $ sudo su -# MYSQL_PASS=nova 设定mysql的密码和nova数据库的密码# cat <<MYSQL_PRESEED | debconf-set-selectio ...

  2. Redis-5.0.0集群配置

    版本:redis-5.0.0 参考:http://redis.io/topics/cluster-tutorial. 集群部署交互式命令行工具:https://github.com/eyjian/re ...

  3. spring之jdbcTemplate

    spring的另一个功能模块data access对于数据库的支持 spring data access第一个helloword案例: 使用java程序实现访问配置 1.导包 2.测试案例 @Test ...

  4. (单调队列) Bad Hair Day -- POJ -- 3250

    http://poj.org/problem?id=3250 Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissi ...

  5. noip第7课资料

  6. java基础-day23

    第11天  面向网络编程 今日内容介绍 u  网络编程概述 u  UDP u  TCP 第1章   网络编程概述 1.1      网络协议 通过计算机网络可以使多台计算机实现连接,位于同一个网络中的 ...

  7. common.php

    <?php /** * */ class Common { if(!function_exists('is_php')) { function is_php($version = '5.0.0' ...

  8. 牛客网2018暑期训练 第三场 a题

    #include <bits/stdc++.h> using namespace std; vector<int> path; ; short dp[maxn][maxn][m ...

  9. 种类并查集——带权并查集——POJ1182;HDU3038

    POJ1182 HDU3038 这两个题比较像(一类题目),属于带权(种类)并查集 poj1182描绘得三种动物种类的关系,按照他一开始给你的关系,优化你的种类关系网络,最后看看再优化的过程中有几处矛 ...

  10. Python自动化开发 - 函数式编程

    本节内容 一.函数式编程 二.高阶函数 1.变量可以指向函数 2.函数名也是变量 3.传入函数 三.返回函数 1.函数作为返回值 2.闭包特性 一.函数式编程 函数是Python内建支持的一种封装,我 ...