changed to .NET5 , + Property injection
This commit is contained in:
12
AutoFacSamples2/AutoFacSamples2.csproj
Normal file
12
AutoFacSamples2/AutoFacSamples2.csproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
35
AutoFacSamples2/Program.cs
Normal file
35
AutoFacSamples2/Program.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using Autofac;
|
||||
using System;
|
||||
|
||||
namespace AutoFacSamples2
|
||||
{
|
||||
public class Parent
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return "I am your father";
|
||||
}
|
||||
}
|
||||
|
||||
public class Child
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Parent Parent { get; set; }
|
||||
}
|
||||
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<Parent>();
|
||||
|
||||
builder.RegisterType<Child>().PropertiesAutowired();
|
||||
|
||||
var container = builder.Build();
|
||||
var parent = container.Resolve<Child>().Parent;
|
||||
Console.WriteLine(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user