changed to .NET5 , + Property injection

This commit is contained in:
2020-11-29 21:15:45 +01:00
parent 5ca347fc6a
commit e2027a5f7e
6 changed files with 59 additions and 6 deletions

View 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>

View 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);
}
}
}