Initial program before inport of autofac
This commit is contained in:
@ -2,11 +2,61 @@
|
|||||||
|
|
||||||
namespace AutoFacSamles
|
namespace AutoFacSamles
|
||||||
{
|
{
|
||||||
|
public interface ILog
|
||||||
|
{
|
||||||
|
void Write(string message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ConsoleLog : ILog
|
||||||
|
{
|
||||||
|
public void Write(string message)
|
||||||
|
{
|
||||||
|
Console.WriteLine(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Engine
|
||||||
|
{
|
||||||
|
private ILog log;
|
||||||
|
private int id;
|
||||||
|
public Engine(ILog log)
|
||||||
|
{
|
||||||
|
this.log = log;
|
||||||
|
id = new Random().Next();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Ahead(int power)
|
||||||
|
{
|
||||||
|
log.Write($"Engine [{id}] ahead {power}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Car
|
||||||
|
{
|
||||||
|
private Engine engine;
|
||||||
|
private ILog log;
|
||||||
|
|
||||||
|
public Car(Engine engine,ILog log)
|
||||||
|
{
|
||||||
|
this.engine = engine;
|
||||||
|
this.log = log;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Go()
|
||||||
|
{
|
||||||
|
engine.Ahead(100);
|
||||||
|
log.Write("Car going forward...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Hello World!");
|
var log = new ConsoleLog();
|
||||||
|
var engine = new Engine(log);
|
||||||
|
var car = new Car(engine, log);
|
||||||
|
car.Go();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user