first use of autofac
This commit is contained in:
@ -5,4 +5,8 @@
|
|||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Autofac" Version="6.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Autofac;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace AutoFacSamles
|
namespace AutoFacSamles
|
||||||
{
|
{
|
||||||
@ -53,9 +54,14 @@ namespace AutoFacSamles
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var log = new ConsoleLog();
|
var builder = new ContainerBuilder();
|
||||||
var engine = new Engine(log);
|
builder.RegisterType<ConsoleLog>().As<ILog>();
|
||||||
var car = new Car(engine, log);
|
builder.RegisterType<Engine>();
|
||||||
|
builder.RegisterType<Car>();
|
||||||
|
|
||||||
|
IContainer container = builder.Build();
|
||||||
|
|
||||||
|
var car = container.Resolve<Car>();
|
||||||
car.Go();
|
car.Go();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user