一、基本配置
1、通过配置的方式使用Autofac
2、通过RegisterModule方式使用配置文件中的信息
static void Main(string[] args) { ContainerBuilder builder = new ContainerBuilder(); builder.RegisterType(); builder.RegisterModule(new ConfigurationSettingsReader("autofac")); using (IContainer container = builder.Build()) { AutoFacManager manager = container.Resolve (); manager.Say(); } Console.ReadKey(); }
3、通过Register的方式
builder.RegisterModule(new ConfigurationSettingsReader("autofac")); builder.Register(c => new AutoFacManager(c.Resolve()));