diff --git a/AutoFacSamples2/Program.cs b/AutoFacSamples2/Program.cs index 14d154d..aa35a45 100644 --- a/AutoFacSamples2/Program.cs +++ b/AutoFacSamples2/Program.cs @@ -15,6 +15,11 @@ namespace AutoFacSamples2 { public string Name { get; set; } public Parent Parent { get; set; } + + public void SetParent(Parent parent) + { + Parent = parent; + } } @@ -25,7 +30,25 @@ namespace AutoFacSamples2 var builder = new ContainerBuilder(); builder.RegisterType(); - builder.RegisterType().PropertiesAutowired(); + //1/builder.RegisterType().PropertiesAutowired(); + + //2/builder.RegisterType() + //2/ .WithProperty("Parent", new Parent()); + + //3/builder.Register(c => + //3/{ + //3/ var child = new Child(); + //3/ child.SetParent(c.Resolve()); + //3/ return child; + //3/}); + + builder.RegisterType() + .OnActivated(e => + { + var p = e.Context.Resolve(); + e.Instance.SetParent(p); + }); + var container = builder.Build(); var parent = container.Resolve().Parent;