changed to .NET5 , + Property injection
This commit is contained in:
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