Choosing constructor when several is defined
This commit is contained in:
@ -46,6 +46,12 @@ namespace AutoFacSamles
|
||||
private Engine engine;
|
||||
private ILog log;
|
||||
|
||||
public Car(Engine engine)
|
||||
{
|
||||
this.engine = engine;
|
||||
this.log = new EmailLog();
|
||||
}
|
||||
|
||||
public Car(Engine engine, ILog log)
|
||||
{
|
||||
this.engine = engine;
|
||||
@ -64,9 +70,10 @@ namespace AutoFacSamles
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<EmailLog>().As<ILog>();
|
||||
builder.RegisterType<ConsoleLog>().As<ILog>();
|
||||
builder.RegisterType<Engine>();
|
||||
builder.RegisterType<Car>();
|
||||
builder.RegisterType<Car>()
|
||||
.UsingConstructor(typeof(Engine));
|
||||
|
||||
IContainer container = builder.Build();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user