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. 常用的ubantu操作命令

    Ubuntu软件操作的相关命令 sudo apt-get update 更新源 sudo apt-get install package 安装包 sudo apt-get remove package ...

  2. 【python 】Requests 库学习笔记

    概览 实例引入 import requests response = requests.get('https://www.baidu.com/') print(type(response)) prin ...

  3. Linux命令之sed批量替换字符串操作

    使用sed命令可以进行字符串的批量替换操作,以节省大量的时间及人力: 使用的格式如下: sed -i "s/oldstring/newstring/g" `grep oldstri ...

  4. 机器学习算法中GBDT和XGBOOST的区别有哪些

    首先xgboost是Gradient Boosting的一种高效系统实现,并不是一种单一算法.xgboost里面的基学习器除了用tree(gbtree),也可用线性分类器(gblinear).而GBD ...

  5. Redis服务器操作

    [Redis服务器操作] 1.TIME 返回当前服务器时间. 2.DBSIZE 返回当前数据库的 key 的数量. 3.LASTSAVE 返回最近一次 Redis 成功将数据保存到磁盘上的时间,以 U ...

  6. 生产者消费者模式做一个golang的定时器

    在主程序启动的时候开一个goroutine作为消费者,用管道连接生产者和消费者,消费者处于无限循环,从管道中获取channel传过来定时event 注意:channel在消费者创建的时候就连通生产者和 ...

  7. Android开发之获取系统所有进程信息。

    最近在做一个app,有一个进程管理模块用于管理系统中正在运行的进程,并且可以关闭进程进行加速手机的功能,基本把它实现了出来.界面的效果都是自己写的,虽然有BUG,但是基本上能满足需求,后期我会改进BU ...

  8. 数据库帮助类 SqlServerHelp

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  9. leetcode 1 A+B problems

    描述: 给个数组和整数t,一串整数中,存在两个数其和等于t,求这两个数的索引. 解决: 想要快,用个哈希储存曾经出现过的数的索引. vector<int> twoSum(vector< ...

  10. 超赞!UX写手必备技能

    以下内容由Mockplus团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具. 今天,小编非常荣幸能与大家一起分享一些优秀UX 写手必备的成功技能: 1.开篇抓住用户的心 MBE曾 ...