.net 4.0使用的DLL #region RegisterType注册 var builder = new ContainerBuilder(); builder.RegisterType<DatabaseManager>(); builder.RegisterType<SqlDatabase>().As<IDatabase>();//通过AS可以让DatabaseManager类中通过构造函数依赖注入类型相应的接口. using (var container =…
实例生命周期决定在同一个服务的每个请求的实例是如何共享的. 当请求一个服务的时候,Autofac会返回一个单例 (single instance作用域), 一个新的对象 (per lifetime作用域) 或者在某种上下文环境中的单例.比如 一个线程 或者一个HTTP请求 (per lifetime 作用域). 这条规则适用于显式调用Resolve从容器中检索对象或者满足依赖而隐式实现的对象. 准备工作: public class Person { public string Name { ge…
泛型类型的注册和使用 public interface IRepository<T> where T:class { } public interface ISchoolDetailRepository : IRepository<SchoolDetail> { } public abstract class RepositoryBase<T> where T : class { private LearningCompactPilotContext _dataCont…