I have a simple application as shown below:
public interface PaymentProcessor
{
void ProcessPayment();
}
public class PaymentProcessorOne : PaymentProcessor
{
public void ProcessPayment()
{
Console.WriteLine("Payment processed by PaymentProcessorOne.");
}
}
public class PaymentProcessorTwo : PaymentProcessor
{
public void ProcessPayment()
{
Console.WriteLine("Payment processed by PaymentProcessorTwo.");
}
}
public class PaymentProcessorThree : PaymentProcessor
{
public void ProcessPayment()
{
Console.WriteLine("Payment processed by PaymentProcessorThree.");
}
}
And I'm registering my types in Program.cs as:
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).AsImplementedInterfaces();
IContainer container = builder.Build();
var processor = container.Resolve<PaymentProcessor>();
processor.ProcessPayment();
First time when I executed this code, the output was "Payment processed by PaymentProcessorTwo". However, when I executed the same code on a different machine the output was "Payment processed by PaymentProcessorThree".
I would like to know how is autofac resolving the PaymentProcessor
in the main logic.