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

最新文章

  1. Linux虚拟机中配置JDK环境变量
  2. GitHub 上 57 款最流行的开源深度学习项目
  3. [Bug]枚举数组,并找到某些元素删除
  4. putty自动登录
  5. WebActivatorEx 注入时的使用
  6. 操作系统:cpu调度 6-25
  7. H264转成RGB24格式-2016.01.21
  8. 01-01-01【Nhibernate (版本3.3.1.4000) 出入江湖】配置文件
  9. 2014-9-17二班----7 web project
  10. nginx配置:location配置方法及实例详解
  11. timestamp ---自动更新修改时间 与 记录首次插入时间
  12. win7系统下连接使用mac 蓝牙键盘(Apple Wireless Keyborad)
  13. window wamp下xhprof的安装使用,Graphviz配置
  14. Generator函数语法解析
  15. 针对Chrome谷歌等浏览器不再支持showModalDialog的解决方案
  16. iOS中 支付宝钱包详解/第三方支付 韩俊强的博客
  17. 如何彻底禁止win10易升更新(转)
  18. Linux: 软件包管理之rpm与yum [转]
  19. day21:包和异常处理
  20. [leetcode]Largest Rectangle in Histogram @ Python

热门文章

  1. PostgreSQL字段名和表名大小写的问题
  2. DDD领域驱动设计基本理论知识总结(转)
  3. JMeter学习笔记(九) 参数化4--User Variables
  4. 【SpringCloud】第一篇: 服务的注册与发现(Eureka)
  5. 1072 Gas Station (30 分)(最短路径)
  6. 用vs调试项目页面无样式
  7. Linux TCP协议使用的变量
  8. linux文件系统(ext2)
  9. golang and intellij
  10. 隐马尔可夫模型HMM