Do I need to register a type before it is resolved?
builder.RegisterType<Driver>().As<IDriver>();
builder.Register(c => new Car(c.Resolve<IDriver>())).As<IVehicle>();
Or can I omit the register type line. Will the resolve register it for me?
Edit
Should I use RegisterType or Register
builder.Register(c => new Driver()).As<IDriver>();
builder.Register(c => new Car(c.Resolve<IDriver>())).As<IVehicle>();
No, you need to register components before you can resolve dependencies on them.
In some specific situations, Autofac’s
AnyConcreteTypeNotAlreadyRegisteredSourcemay automate the process.More often,
ContainerBuilder.RegisterAssemblyTypes()is used to batch up registrations and cut down on repetition.