ASP.NET Core四大部件
四大部件
(WebHost,Startup,launchSettings,wwwroot)

WebHost
简单理解是一个socket,
https://www.cnblogs.com/neverc/p/7988226.html (好)

Startup
Startup.cs文件是ASP.NET Core的启动入口文件,想必尝试过OWIN开发的一定不会陌生。项目运行时,编译器会在程序集中自动查找Startup.cs文件读取启动配置。除了构造函数外,它可以定义Configure和ConfigureServices方法。
ConfigureServices
给程序员添加一些服务的代码区
比如AddMvc查看mvc源码
internal static void AddViewServices(IServiceCollection services)
{
DataProtectionServiceCollectionExtensions.AddDataProtection(services);
AntiforgeryServiceCollectionExtensions.AddAntiforgery(services);
EncoderServiceCollectionExtensions.AddWebEncoders(services);
ServiceCollectionDescriptorExtensions.TryAddEnumerable(services, ServiceDescriptor.Transient<IConfigureOptions<MvcViewOptions>, MvcViewOptionsSetup>());
ServiceCollectionDescriptorExtensions.TryAddEnumerable(services, ServiceDescriptor.Transient<IPostConfigureOptions<MvcViewOptions>, MvcViewOptionsConfigureCompatibilityOptions>());
ServiceCollectionDescriptorExtensions.TryAddEnumerable(services, ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, TempDataMvcOptionsSetup>());
ServiceCollectionDescriptorExtensions.TryAddSingleton<ICompositeViewEngine, CompositeViewEngine>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<IActionResultExecutor<ViewResult>, ViewResultExecutor>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<IActionResultExecutor<PartialViewResult>, PartialViewResultExecutor>(services);
ServiceCollectionDescriptorExtensions.TryAddEnumerable(services, ServiceDescriptor.Transient<IControllerPropertyActivator, ViewDataDictionaryControllerPropertyActivator>());
ServiceCollectionDescriptorExtensions.TryAddTransient<IHtmlHelper, HtmlHelper>(services);
ServiceCollectionDescriptorExtensions.TryAddTransient(services, typeof(IHtmlHelper<>), typeof(HtmlHelper<>));
ServiceCollectionDescriptorExtensions.TryAddSingleton<IHtmlGenerator, DefaultHtmlGenerator>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<ExpressionTextCache>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<IModelExpressionProvider, ModelExpressionProvider>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<ValidationHtmlAttributeProvider, DefaultValidationHtmlAttributeProvider>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<IJsonHelper, JsonHelper>(services);
ServiceCollectionDescriptorExtensions.TryAdd(services, ServiceDescriptor.Singleton<JsonOutputFormatter>(delegate (IServiceProvider serviceProvider) {
return new JsonOutputFormatter(ServiceProviderServiceExtensions.GetRequiredService<IOptions<MvcJsonOptions>>(serviceProvider).get_Value().get_SerializerSettings(), ServiceProviderServiceExtensions.GetRequiredService<ArrayPool<char>>(serviceProvider));
}));
ServiceCollectionDescriptorExtensions.TryAddSingleton<IViewComponentSelector, DefaultViewComponentSelector>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<IViewComponentFactory, DefaultViewComponentFactory>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<IViewComponentActivator, DefaultViewComponentActivator>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<IViewComponentDescriptorCollectionProvider, DefaultViewComponentDescriptorCollectionProvider>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<IActionResultExecutor<ViewComponentResult>, ViewComponentResultExecutor>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<ViewComponentInvokerCache>(services);
ServiceCollectionDescriptorExtensions.TryAddTransient<IViewComponentDescriptorProvider, DefaultViewComponentDescriptorProvider>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>(services);
ServiceCollectionDescriptorExtensions.TryAddTransient<IViewComponentHelper, DefaultViewComponentHelper>(services);
ServiceCollectionDescriptorExtensions.TryAddEnumerable(services, ServiceDescriptor.Transient<IApplicationModelProvider, TempDataApplicationModelProvider>());
ServiceCollectionDescriptorExtensions.TryAddEnumerable(services, ServiceDescriptor.Transient<IApplicationModelProvider, ViewDataAttributeApplicationModelProvider>());
ServiceCollectionDescriptorExtensions.TryAddSingleton<SaveTempDataFilter>(services);
ServiceCollectionDescriptorExtensions.TryAddTransient<ControllerSaveTempDataPropertyFilter>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<ITempDataProvider, CookieTempDataProvider>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<ValidateAntiforgeryTokenAuthorizationFilter>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<AutoValidateAntiforgeryTokenAuthorizationFilter>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<ITempDataDictionaryFactory, TempDataDictionaryFactory>(services);
ServiceCollectionDescriptorExtensions.TryAddSingleton<ArrayPool<ViewBufferValue>>(services, ArrayPool<ViewBufferValue>.get_Shared());
ServiceCollectionDescriptorExtensions.TryAddScoped<IViewBufferScope, MemoryPoolViewBufferScope>(services);
}
MVC大概注册了100多的服务。。。
Configure
Configure 方法用于处理我们程序中的各种中间件,这些中间件决定了我们的应用程序将如何响应每一个 HTTP 请求。它必须接收一个IApplicationBuilder参数,我们可以手动补充IApplicationBuilder的Use扩展方法,将中间件加到Configure中,用于满足我们的需求。
<1> 这个方法用于在初始化的时候,将所有的中间件添加到 IApplicationBuilder 的componets数组中。
在Request请求发起的时候,按照添加顺序执行一次中间件,具体的我们下一节课说。
。。。。。。 这个方法配置的东西,只会在Request请求的过程中被调用 。。。。。。
<2> 这个方法的参数是不固定的,只要容器里面有,都可以实现依赖注入。。比如ILoggerFactory logger
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
环境的不同,程序的行为也不一样。。
launchSettings.json
解决问题:快速的做环境切换,方便调试和开发。
目的:让你的程序在多环境一样保持稳定。
1. 直接修改文件。
2. 使用vs面板。

wwwroot
存放静态资源

ASP.NET Core四大部件的更多相关文章
- ASP.NET Core 中文文档 第四章 MVC(3.7 )局部视图(partial)
原文:Partial Views 作者:Steve Smith 翻译:张海龙(jiechen).刘怡(AlexLEWIS) 校对:许登洋(Seay).何镇汐.魏美娟(初见) ASP.NET Core ...
- ASP.NET Core: 全新的ASP.NET !
背景 最新版本的 ASP.NET 叫做 ASP.NET Core (也被称为 ASP.NET 5) 它颠覆了过去的 ASP.NET. 什么是 ASP.NET Core? ASP.NET Core ...
- ASP.NET Core重写个人博客站点小结
今天用ASP.NET Core重写了个人博客站点,原来是基于ASP.NET 4.5开发的.重写工作总体很顺利,最后成功发布到Ubunt+Nginx平台上.效果如下: 右边的Header信息里可以看到已 ...
- 【翻译】在Mac上使用VSCode创建你的第一个Asp.Net Core应用
Setting Up Your Development Environment 设置你的开发环境 To setup your development machine download and inst ...
- ubuntu下发布asp.net core并用nginx代理之旅
asp.net core 1.0.1发布已有些日子了,怀着好奇的心情体验了把ubuntu下的asp.net core 系统运行环境:ubuntu 16.0.4 for developer 首先搭建.n ...
- ASP.NET Core的身份认证框架IdentityServer4(9)-使用OpenID Connect添加用户认证
OpenID Connect OpenID Connect 1.0是OAuth 2.0协议之上的一个简单的身份层. 它允许客户端基于授权服务器执行的身份验证来验证最终用户的身份,以及以可互操作和类似R ...
- 向ASP.NET Core迁移
有人说.NET在国内的氛围越来越不行了,看博客园文章的浏览量也起不来.是不是要转Java呢? 没有必要扯起语言的纷争,Java也好C#都只是语言是工具,各有各的使用场景.以前是C#非开源以及不能在Li ...
- ASP.NET Core 认证与授权[6]:授权策略是怎么执行的?
在上一章中,详细介绍了 ASP.NET Core 中的授权策略,在需要授权时,只需要在对应的Controler或者Action上面打上[Authorize]特性,并指定要执行的策略名称即可,但是,授权 ...
- 【ASP.NET Core】JSON Patch 使用简述
JSON Patch 是啥玩意儿?不知道,直接翻译吧,就叫它“Json 补丁”吧.干吗用的呢?当然是用来修改 JSON 文档的了.那咋修改呢?比较常见有四大操作:AMRR. 咋解释呢? A—— Add ...
随机推荐
- Ruby on Rails框架(1)-安装全攻略
序 关于Rails的三句箴言 (1)DRY:Don't Repeat Yourself(不要重复你自己) rails的开发理念,不要用你的代码不停的重复,rails框架给开发者提供了一套非常完善的支持 ...
- Complete the Projects
F1. Complete the Projects (easy version) F2. Complete the Projects (hard version) 参考:Complete the Pr ...
- phpMyadmin各个版本漏洞【转载】
原作者:热爱网络安全的小菜狗 原文链接:phpMyadmin各版本漏洞 0x01 PREGREPLACEEVAL漏洞 影响版本:3.5.x < 3.5.8.1 and 4.0.0 < 4. ...
- vim 文本替换讲解
在VIM中进行文本替换: 1. 替换当前行中的内容: :s/from/to/ (s即substitude) :s/from/to/ : 将当前行中的第一个from,替换成to.如果当前行含有多个 fr ...
- Python2和Python3共存问题
前提条件:先准备一个新电脑 1.下载Python2和Python3的安装包,直接官网下载:https://www.python.org/download 2.配置环境变量,可以手动配置,也可以安装的时 ...
- Unity编辑器环境在Inspector面板中显示变量
Serialize功能Unity3D 中提供了非常方便的功能可以帮助用户将 成员变量 在Inspector中显示,并且定义Serialize关系. 简单的说,在没有自定义Inspector的情况下所有 ...
- Java_jdbc 基础笔记之三 数据库连接 (Statement)
/** * 通过JDBC向之指定的数据表中插入一条记录 1 Statement :用于执行SQL语句的对象 * ==>通过Connection的createStatement()方法来获取 == ...
- C/C++/Linux编程经典电子书pdf下载
实际上目前Linux下C开发一般都是C++实现下的C,而不是最纯粹的C,使用g++而不是gcc编译,所以直接学习C++的过程性C部分是更加高效的. C++ Primer(中文版 第5版)C++学习头牌 ...
- 常忘知识点三-使用选择器继承来精简CSS --- @extend
推荐一个很详细的sass教程:https://www.sass.hk/docs/ 在设计网页的时候常常遇到这种情况:一个元素使用的样式与另一个元素完全相同,但又添加了额外的样式.通常会在 HTML 中 ...
- MiniUI表单验证实践
学习实践: <form id="form2"> <div id="update_pas" style="width:380px&qu ...