mvc_study

*:first-child {
margin-top: 0 !important;
}

body>*:last-child {
margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}

h1 {
font-size: 28px;
color: #000;
}

h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}

h3 {
font-size: 18px;
}

h4 {
font-size: 16px;
}

h5 {
font-size: 14px;
}

h6 {
color: #777;
font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
color: #4183C4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
padding-left: 30px;
}

ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}

dl {
padding: 0;
}

dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}

dl dt:first-child {
padding: 0;
}

dl dt>:first-child {
margin-top: 0px;
}

dl dt>:last-child {
margin-bottom: 0px;
}

dl dd {
margin: 0 0 15px;
padding: 0 15px;
}

dl dd>:first-child {
margin-top: 0px;
}

dl dd>:last-child {
margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}

pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}

pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}

pre code, pre tt {
background-color: transparent;
border: none;
}

kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}

blockquote>:first-child {
margin-top: 0px;
}

blockquote>:last-child {
margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}

/* TABLES
=============================================================================*/

table th {
font-weight: bold;
}

table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}

table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}

table tr:nth-child(2n) {
background-color: #f8f8f8;
}

/* IMAGES
=============================================================================*/

img {
max-width: 100%
}
-->

StudyStartup

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Web.Study.ConfigModel;
using Web.Study.MonsterInterface; namespace Web.Study.InhertStartup
{
public class StudyStartup
{ protected IConfiguration Configuration { get; set; } public StudyStartup()
{ } /// <summary>
/// 用于获取配置信息
/// </summary>
/// <param name="configuration"></param>
public StudyStartup(IConfiguration configuration)
{
Configuration = configuration;
} public IServiceProvider ConfigureServices(IServiceCollection services)
{ //注入mvc
services.AddMvc(); //添加Options
services.AddOptions(); //获取配置信息
services.Configure<AppSetting>(Configuration.GetSection(nameof(AppSetting))); //开启Session功能
services.AddSession(options ={
options.IdleTimeout = TimeSpan.FromMinutes(30);
}); //构建一个默认的serviceProvider处理对象
return services.BuildServiceProvider();
} public void Configure(IApplicationBuilder app,
IHostingEnvironment environment,
ILoggerFactory loggerFactory,
IHttpContextFactory httpContextFactory,
DiagnosticSource diagnosticSource,
DiagnosticListener diagnosticListener)
{
//当前环境为开发环境
if (environment.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
} // 重要: session的注册必须在UseMvc之前,因为MVC里面要用
app.UseSession(); //使用webroot中的静态文件
app.UseStaticFiles(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}

Program

    public static IWebHost BuildWebHost<T>(string[] args) where T:class
{
IWebHostBuilder webHostBuilder = WebHost.CreateDefaultBuilder(args); IWebHostBuilder hostBuilder = webHostBuilder.UseStartup<T>(); IWebHost webHost = hostBuilder.Build(); return webHost; }

code explain

construction

public StudyStartup(IConfiguration configuration)

相关源码
IWebHostBuilder webHostBuilder = WebHost.CreateDefaultBuilder(args); 方法解析 public static IWebHostBuilder CreateDefaultBuilder(string[] args)
{
return new WebHostBuilder()
.UseKestrel()//Specify Kestrel as the server to be used by the web host.
.UseContentRoot(Directory.GetCurrentDirectory())//采用当前目录作为内容跟目录
//配置信息处理
.ConfigureAppConfiguration((Action<WebHostBuilderContext, IConfigurationBuilder>) ((hostingContext, config) =>
{
//注入运行环境
IHostingEnvironment hostingEnvironment = hostingContext.HostingEnvironment;
//加载配置文件
config.AddJsonFile("appsettings.json", true, true).AddJsonFile(string.Format("appsettings.{0}.json", (object) hostingEnvironment.EnvironmentName), true, true);
//根据运行环境加载相应文件
if (hostingEnvironment.IsDevelopment())
{
Assembly assembly = Assembly.Load(new AssemblyName(hostingEnvironment.ApplicationName));
if (assembly != (Assembly) null)
config.AddUserSecrets(assembly, true);
} config.AddEnvironmentVariables();
if (args == null)
return;
config.AddCommandLine(args);
}))
//配置日志信息
.ConfigureLogging((Action<WebHostBuilderContext, ILoggingBuilder>) ((hostingContext, logging) =>
{
logging.AddConfiguration((IConfiguration) hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.AddDebug();
}))
.UseIISIntegration()//采用IIS进行发布
.UseDefaultServiceProvider((Action<WebHostBuilderContext, ServiceProviderOptions>) ((context, options) => options.ValidateScopes = context.HostingEnvironment.IsDevelopment()));//采用默认的处理机制
}

即若需要使用startup的有参构造,则需要在configureappconfiguration中进行配置相应处理类

请求走向:

初始:Run --> ConfigureServices --> Configure

配置信息的获取:

<Controller>

protected AppSetting ConfigInfo { get; set; }

    //读取配置信息
protected BaseController(IOptions<AppSetting> options) => ConfigInfo = options.Value;

DI注入

1.创建的DI注入在ConfigureServices进行处理

注入方式:

services.AddSingleton(u => new MonsterDIController(new GuestDal()));//指定控制器进行注入

services.AddSingleton<IDal,DefaultDal>();//统一注入  全局共享一个

services.AddTransient<IDal, DefaultDal>();//统一注入    每次使用都不一样,不同的类或不同的方法使用都不一样

services.AddScoped<IDal, EmptyDal>();//统一注入   一次请求共享一个对象

注:
当对同一类型构造传入不同类型对象的注入时,
不考虑注入类型或范围
已最终注入类型为传入对象创建实例 例如:
<Controller> protected IDal Dal { get; set; } public MonsterDIController(IDal dal)
{
this.Dal = dal;
} <ConfigureServices>
如上述一致 <Result>
最终创建实例时,会传入EmptyDal

开启Session功能:

<method --> ConfigureServices>

    services.AddSession(options => {
options.IdleTimeout = TimeSpan.FromMinutes(30);//存储时长
}); <method --> Configure >
// 重要: session的注册必须在UseMvc之前,因为MVC里面要用
app.UseSession();

.net core 2.0 mvc 初步学习的更多相关文章

  1. ASP.NET Core 2.0 MVC项目实战

    一.前言 毕业后入职现在的公司快有一个月了,公司主要的产品用的是C/S架构,再加上自己现在还在学习维护很老的delphi项目,还是有很多不情愿的.之前实习时主要是做.NET的B/S架构的项目,主要还是 ...

  2. ASP.NET CORE 1.0 MVC API 文档用 SWASHBUCKLE SWAGGER实现

    from:https://damienbod.com/2015/12/13/asp-net-5-mvc-6-api-documentation-using-swagger/ 代码生成工具: https ...

  3. .net core 2.0 mvc 获取配置信息

    mvc_core_config *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 ...

  4. asp.net core 3.0 MVC JSON 全局配置

    asp.net core 3.0 MVC JSON 全局配置 System.Text.Json(default) startup配置代码如下: using System.Text.Encodings. ...

  5. 使用VS Code开发.Net Core 2.0 MVC Web应用程序教程之一

    好吧,现在我们假设你已经安装好了VS Code开发工具..Net Core 2.0预览版的SDK dotnet-sdk-2.0.0(注意自己的操作系统),并且已经为VS Code安装好了C#扩展(在V ...

  6. asp.net Core 2.0 MVC为Controller或Action添加定制特性实现登录验证

    前言:最近在倒腾 微软的新平台 asp.net Core 2.0,在这个过程中有些东西还是存在差异.下面是我在学习过程的一点笔记.有不妥之处,望各位大虾指正! 一.先创建一个控制器继承于Control ...

  7. ASP.NET Core 2.0 MVC 发布部署--------- CentOS7 X64 具体操作

    .Net Core 部署到 CentOS7 64 位系统中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是 ...

  8. ASP.NET Core 2.0 MVC 发布部署--------- SUSE 16 Linux Enterprise Server 12 SP2 X64 具体操作

    .Net Core 部署到 SUSE 16 Linux Enterprise Server 12 SP2 64 位中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk ...

  9. ASP.NET Core 2.0 MVC 发布部署--------- Ubuntun 16.04 X64 具体操作

    .Net Core 部署到Ubuntu 16.04 中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是服务 ...

随机推荐

  1. 全虚拟化和半虚拟化的区别 cpu的ring0~ring3又是什么概念?

    ring0是指CPU的运行级别,ring0是最高级别,ring1次之,ring2更次之-- 拿Linux+x86来说, 操作系统(内核)的代码运行在最高运行级别ring0上,可以使用特权指令,控制中断 ...

  2. Spring配置项<context:annotation-config/>解释说明

    转自:https://blog.csdn.net/techbirds_bao/article/details/9241371 在基于主机方式配置Spring的配置文件中,你可能会见到<conte ...

  3. 8 MySQL--单表查询

    单表查询: http://www.cnblogs.com/linhaifeng/articles/7267592.html 1.单表查询的语法 2.关键字的执行优先级(重点) 3.简单查询 4.whe ...

  4. 快速变幻AABB的顶点

    [快速变幻AABB的顶点] 当要变幻一个AABB时,可以快速计算变幻后顶点的AABB.当有旋转时,根据8个顶点变幻后的AABB可能会更大. AABB的八个顶点需分别作如下变幻: 注意到为了使 x' 最 ...

  5. METAL渲染是什么?

    METAL渲染是什么? Metal渲染是由苹果公司为iOS8以及更新版本开发的全新的底层渲染API.它侧重于减少GPU驱动的工作量,从而当Metal调用时,CPU的消耗将降至最低.这样一来,游戏就可以 ...

  6. Python全栈工程师(Python3 所有基础内容 0-0)

    ParisGabriel              每天坚持手写  一天一篇  决定坚持几年 为了梦想为了信仰    开局一张图     Python一个月的基础语法 基本就到这咯    接下来是数据 ...

  7. 存储过程返回update结果集和insert主键

    update teacher set name ='111' where id in(286,289);print @@rowcount;--或select将查出,是@@rowcount,不是@row ...

  8. ORA-01795: maximum number of expressions in a list is 1000

     今天发现查询Oracle用In查询In的元素不可以超过1000个还需要分成多个1000查询记录博客备忘!! Load Test的时候发现这么如下这个错误.... ORA-01795: maximum ...

  9. day24,python习题

    今日作业 有两个列表,分别存放来老男孩报名学习linux和python课程的学生名字 linux=['钢弹','小壁虎','小虎比','alex','wupeiqi','yuanhao'] pytho ...

  10. VMware CentOS LVM磁盘扩容

    一. 在虚拟机上增加磁盘空间 如下图. 增加完后会有提示 "磁盘已成功扩展.您必须从客户机操作系统内部对磁盘重新进行分区和扩展文件系统.是继续完成以下步骤才算成功. 二.调整虚拟机磁盘LVM ...