Autofac三种生命周期

InstancePerLifetimeScope:同一个Lifetime生成的对象是同一个实例


SingleInstance:单例模式,每次调用,都会使用同一个实例化的对象;每次都用同一个对象;


InstancePerDependency:默认模式,每次调用,都会重新实例化对象;每次请求都创建一个新的对象;

builder.RegisterAssemblyTypes(System.Reflection.Assembly.GetExecutingAssembly()).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces().InstancePerDependency().PropertiesAutowired();//属性注入,默认构造函数注入

原文地址:https://www.cnblogs.com/sylone/p/11014477.html