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();

最新文章

  1. GUI生成exe文件
  2. 关于yuv格式
  3. dll学习
  4. tortoiseSVN svn+ssh
  5. ios中strong和weak的解释理解
  6. java 中获取文件路径
  7. 学习之spring属性文件注入
  8. Android 应用自动更新功能的代码
  9. jfinal不能正确加载html网页,总是报错的解决方法
  10. zedGraph
  11. js星级评分点击星级评论打分效果--收藏--转载
  12. (原)lua使用ffi调用c程序的函数
  13. java python oracle推断字符串是否为数字的函数
  14. cocos2D(五岁以下儿童)---- CCNode
  15. python3环境搭建(uWSGI+django+nginx+python+MySQL)
  16. centos7破解安装jira6.3.6(含Agile)
  17. RabbitMQ:MSVCR120.dll ,c000001d 错误
  18. 20165235 实验二Java面向对象程序设计
  19. 10 BPMN PDF books, articles and brochures
  20. J - Oil Skimming 二分图的最大匹配

热门文章

  1. springcloud(四) ribbon和feign
  2. Hadoop 2.7.3 安装配置及测试
  3. C#串口编程测试收发
  4. 「小程序JAVA实战」小程序查看视频发布者信息(64)
  5. gen_projective_mosaic(Halcon例子)
  6. OpenLayers3 学习-1
  7. 迷你MVVM框架 avalonjs 0.92发布
  8. 归纳整理Linux下C语言常用的库函数----内存及字符串控制及操作
  9. redis客户端执行命令没反应
  10. 28. Implement strStr() (String)