DotNETCore 学习笔记 依赖注入和多环境
- Dependency Injection
- ------------------------------------------------------------------------
- ASP.NET services can be configured with the following lifetimes:
- Transient
- Transient lifetime services are created each time they are requested. This lifetime works best for
- lightweight, stateless services.
- Scoped
- Scoped lifetime services are created once per request.
- Singleton
- Singleton lifetime services are created the first time they are requested (or when ConfigureServices is run
- if you specify an instance there) and then every subsequent request will use the same instance. If your
- application requires singleton behavior, allowing the services container to manage the service’s lifetime
- is recommended instead of implementing the singleton design pattern and managing your object’s lifetime in
- the class yourself.
- **********************************************************************************
- "dependencies" : {
- "Autofac": "4.0.0",
- "Autofac.Extensions.DependencyInjection": "4.0.0"
- },
- public IServiceProvider ConfigureServices(IServiceCollection services)
- {
- services.AddMvc();
- // add other framework services
- // Add Autofac
- var containerBuilder = new ContainerBuilder();
- containerBuilder.RegisterModule<DefaultModule>();
- containerBuilder.Populate(services);
- var container = containerBuilder.Build();
- return new AutofacServiceProvider(container);
- }
- public class DefaultModule : Module
- {
- protected override void Load(ContainerBuilder builder)
- {
- builder.RegisterType<CharacterRepository>().As<ICharacterRepository>();
- }
- }
- **********************************************************************************
- Working with Multiple Environments
- ASPNETCORE_ENVIRONMENT:Development, Staging, and Production
- env.IsEnvironment("environmentname")
- or
- env.EnvironmentName == "Development"
- Startup{EnvironmentName} (for example StartupDevelopment)
- Configure{EnvironmentName}() ConfigureDevelopment()
- Configure{EnvironmentName}Services(). ConfigureDevelopmentServices()
DotNETCore 学习笔记 依赖注入和多环境的更多相关文章
- Spring 学习笔记 ----依赖注入
依赖注入 有三种方式,本文只学习下属性注入. 属性注入 属性注入即通过 setXxx方法()注入Bean的属性值或依赖对象,由于属性注入方式具有可选择性和灵活性高的优点,因此属性注入方式是 ...
- net5学习笔记---依赖注入
小王的故事 小王去上班 小王是个程序员,每个工作日他都要去上班,诸多交通工具他最喜欢的交通工具是骑电车.在骑行的过程中放空自己使他很快. 突然有一天天气预报说近期有很大的雨,小王再想骑电车去上 ...
- Spring学习笔记--依赖注入
依赖注入和控制反转:http://baitai.iteye.com/blog/792980出自李刚<轻量级 Java EE 企业应用实战> Java应用是一种典型的依赖型应用,它就是由一些 ...
- Swift学习笔记(一)搭配环境以及代码运行成功
原文:Swift学习笔记(一)搭配环境以及代码运行成功 1.Swift是啥? 百度去!度娘告诉你它是苹果最新推出的编程语言,比c,c++,objc要高效简单.能够开发ios,mac相关的app哦!是苹 ...
- Django学习笔记(一):环境安装与简单实例
Django学习笔记(一):环境安装与简单实例 通过本文章实现: Django在Windows中的环境安装 Django项目的建立并编写简单的网页,显示欢迎语与当前时间 一.环境安装 结合版本兼容性等 ...
- ADO学习笔记之注入漏洞与参数化查询
ADO学习笔记之注入漏洞与参数化查询 作为新手,在学习ADO程序时,使用 sql 语言查询数据时,很容易写类似如下代码: using (SqlConnection con = new SqlConne ...
- kvm虚拟化学习笔记(一)之kvm虚拟化环境安装
平时一直玩RHEL/CentOS/OEL系列的操作,玩虚拟化也是采这一类系统,kvm在RHEL6系列操作系统支持比较好,本文采用采用OEL6.3操作系统,网上所有文章都说KVM比xen简单,我怎么感觉 ...
- Orleans[NET Core 3.1] 学习笔记(一).NET环境下的分布式应用程序
前言 Orleans是一个跨平台的框架,用于搭建可扩展的分布式应用程序 第一次接触Orleans还是两年前做游戏服务器的时候,用SignalR+Orleans的组合,写起代码来不要太爽. 即将进入20 ...
- Java web与web gis学习笔记(一)——Tomcat环境搭建
系列链接: Java web与web gis学习笔记(一)--Tomcat环境搭建 Java web与web gis学习笔记(二)--百度地图API调用 JavaWeb和WebGIS学习笔记(三)-- ...
随机推荐
- [转] Bash脚本:怎样一行行地读文件(最好和最坏的方法)
用bash脚本读文件的方法有很多.请看第一部分,我使用了while循环及其后的管道命令(|)(cat $FILE | while read line; do … ),并在循环当中递增 i 的值,最后, ...
- PostgreSQL 10.0 压缩版的 pgAdmin 不能用的问题
PostgreSQL终于发布10.0正式版了!下载压缩版的更新了一下本机的版本,然后打开pgAdmin的时候总是报错“The application server could not be conta ...
- SVN 使用时的小错误
在使用SVN的时候总是出现一些小问题,今天又出现了一个,诶,分享一下吧! Error:(个人文件夹名http://www.qdjhu.com/anli_xq/f_wancheng.php) is ...
- 在Android上,怎样与Kotlin一起使用Retrofit(KAD21)
作者:Antonio Leiva 时间:Apr 18, 2017 原文链接:https://antonioleiva.com/retrofit-android-kotlin/ 这是又一个例子,关于怎样 ...
- 简易cmake多文件多目录工程模板
今天心血来潮,想在服务器上试试写libevent的工程是什么感受,那第一步就是学会怎么用cmake建工程,之前也没接触过cmake,然后一上午,比较懵逼,下午看实验室哥们给的一个教程,然后,慢慢理解C ...
- [leetcode-640-Solve the Equation]
Solve a given equation and return the value of x in the form of string "x=#value". The equ ...
- mac下使用clion构建boost库
mac下使用clion构建boost库 使用brew install boost 完成后发现boost被安装在在/usr/local/Cellar/boost下 jetbrain给出的指导意见 htt ...
- epc笔记
http://wenku.baidu.com/view/5e921520dd36a32d7375812a.html 1. 先注册, EPC注册EPS业务或non-EPS服务 ?? HSS做什么? 2 ...
- 使用window.getSelection()获取div中选中文字内容及位置
div添加一个弹出事件: $(document).ready(function () { $("#marked-area").mouseup(function (e) { $sco ...
- servlet 接受和回复向服务器对客户端发起得请求
servlet 接受和回复向服务器对客户端发起得请求