1. Dependency Injection
  2. ------------------------------------------------------------------------
  3. ASP.NET services can be configured with the following lifetimes:
  4.  
  5. Transient
  6. Transient lifetime services are created each time they are requested. This lifetime works best for
  7.  
  8. lightweight, stateless services.
  9.  
  10. Scoped
  11. Scoped lifetime services are created once per request.
  12.  
  13. Singleton
  14. Singleton lifetime services are created the first time they are requested (or when ConfigureServices is run
  15.  
  16. if you specify an instance there) and then every subsequent request will use the same instance. If your
  17.  
  18. application requires singleton behavior, allowing the services container to manage the services lifetime
  19.  
  20. is recommended instead of implementing the singleton design pattern and managing your objects lifetime in
  21.  
  22. the class yourself.
  23.  
  24. **********************************************************************************
  25. "dependencies" : {
  26. "Autofac": "4.0.0",
  27. "Autofac.Extensions.DependencyInjection": "4.0.0"
  28. },
  29.  
  30. public IServiceProvider ConfigureServices(IServiceCollection services)
  31. {
  32. services.AddMvc();
  33. // add other framework services
  34.  
  35. // Add Autofac
  36. var containerBuilder = new ContainerBuilder();
  37. containerBuilder.RegisterModule<DefaultModule>();
  38. containerBuilder.Populate(services);
  39. var container = containerBuilder.Build();
  40. return new AutofacServiceProvider(container);
  41. }
  42.  
  43. public class DefaultModule : Module
  44. {
  45. protected override void Load(ContainerBuilder builder)
  46. {
  47. builder.RegisterType<CharacterRepository>().As<ICharacterRepository>();
  48. }
  49. }
  50.  
  51. **********************************************************************************
  52.  
  53. Working with Multiple Environments
  54.  
  55. ASPNETCORE_ENVIRONMENTDevelopment, Staging, and Production
  56.  
  57. env.IsEnvironment("environmentname")
  58. or
  59. env.EnvironmentName == "Development"
  60.  
  61. Startup{EnvironmentName} (for example StartupDevelopment)
  62.  
  63. Configure{EnvironmentName}() ConfigureDevelopment()
  64.  
  65. Configure{EnvironmentName}Services(). ConfigureDevelopmentServices()

DotNETCore 学习笔记 依赖注入和多环境的更多相关文章

  1. Spring 学习笔记 ----依赖注入

    依赖注入 有三种方式,本文只学习下属性注入. 属性注入       属性注入即通过 setXxx方法()注入Bean的属性值或依赖对象,由于属性注入方式具有可选择性和灵活性高的优点,因此属性注入方式是 ...

  2. net5学习笔记---依赖注入

    小王的故事 小王去上班 ​ 小王是个程序员,每个工作日他都要去上班,诸多交通工具他最喜欢的交通工具是骑电车.在骑行的过程中放空自己使他很快. ​ 突然有一天天气预报说近期有很大的雨,小王再想骑电车去上 ...

  3. Spring学习笔记--依赖注入

    依赖注入和控制反转:http://baitai.iteye.com/blog/792980出自李刚<轻量级 Java EE 企业应用实战> Java应用是一种典型的依赖型应用,它就是由一些 ...

  4. Swift学习笔记(一)搭配环境以及代码运行成功

    原文:Swift学习笔记(一)搭配环境以及代码运行成功 1.Swift是啥? 百度去!度娘告诉你它是苹果最新推出的编程语言,比c,c++,objc要高效简单.能够开发ios,mac相关的app哦!是苹 ...

  5. Django学习笔记(一):环境安装与简单实例

    Django学习笔记(一):环境安装与简单实例 通过本文章实现: Django在Windows中的环境安装 Django项目的建立并编写简单的网页,显示欢迎语与当前时间 一.环境安装 结合版本兼容性等 ...

  6. ADO学习笔记之注入漏洞与参数化查询

    ADO学习笔记之注入漏洞与参数化查询 作为新手,在学习ADO程序时,使用 sql 语言查询数据时,很容易写类似如下代码: using (SqlConnection con = new SqlConne ...

  7. kvm虚拟化学习笔记(一)之kvm虚拟化环境安装

    平时一直玩RHEL/CentOS/OEL系列的操作,玩虚拟化也是采这一类系统,kvm在RHEL6系列操作系统支持比较好,本文采用采用OEL6.3操作系统,网上所有文章都说KVM比xen简单,我怎么感觉 ...

  8. Orleans[NET Core 3.1] 学习笔记(一).NET环境下的分布式应用程序

    前言 Orleans是一个跨平台的框架,用于搭建可扩展的分布式应用程序 第一次接触Orleans还是两年前做游戏服务器的时候,用SignalR+Orleans的组合,写起代码来不要太爽. 即将进入20 ...

  9. Java web与web gis学习笔记(一)——Tomcat环境搭建

    系列链接: Java web与web gis学习笔记(一)--Tomcat环境搭建 Java web与web gis学习笔记(二)--百度地图API调用 JavaWeb和WebGIS学习笔记(三)-- ...

随机推荐

  1. [转] Bash脚本:怎样一行行地读文件(最好和最坏的方法)

    用bash脚本读文件的方法有很多.请看第一部分,我使用了while循环及其后的管道命令(|)(cat $FILE | while read line; do … ),并在循环当中递增 i 的值,最后, ...

  2. PostgreSQL 10.0 压缩版的 pgAdmin 不能用的问题

    PostgreSQL终于发布10.0正式版了!下载压缩版的更新了一下本机的版本,然后打开pgAdmin的时候总是报错“The application server could not be conta ...

  3. SVN 使用时的小错误

    在使用SVN的时候总是出现一些小问题,今天又出现了一个,诶,分享一下吧!  Error:(个人文件夹名http://www.qdjhu.com/anli_xq/f_wancheng.php)  is ...

  4. 在Android上,怎样与Kotlin一起使用Retrofit(KAD21)

    作者:Antonio Leiva 时间:Apr 18, 2017 原文链接:https://antonioleiva.com/retrofit-android-kotlin/ 这是又一个例子,关于怎样 ...

  5. 简易cmake多文件多目录工程模板

    今天心血来潮,想在服务器上试试写libevent的工程是什么感受,那第一步就是学会怎么用cmake建工程,之前也没接触过cmake,然后一上午,比较懵逼,下午看实验室哥们给的一个教程,然后,慢慢理解C ...

  6. [leetcode-640-Solve the Equation]

    Solve a given equation and return the value of x in the form of string "x=#value". The equ ...

  7. mac下使用clion构建boost库

    mac下使用clion构建boost库 使用brew install boost 完成后发现boost被安装在在/usr/local/Cellar/boost下 jetbrain给出的指导意见 htt ...

  8. epc笔记

    http://wenku.baidu.com/view/5e921520dd36a32d7375812a.html 1.  先注册, EPC注册EPS业务或non-EPS服务 ?? HSS做什么? 2 ...

  9. 使用window.getSelection()获取div中选中文字内容及位置

    div添加一个弹出事件: $(document).ready(function () { $("#marked-area").mouseup(function (e) { $sco ...

  10. servlet 接受和回复向服务器对客户端发起得请求

    servlet 接受和回复向服务器对客户端发起得请求