A LazyProxy can be used for IoC containers to change the resolving behaviour.
Dependencies registered as lazy are created as dynamic proxy objects built in real time, but the real classes are resolved only after the first execution of proxy method or property.
Also dynamic lazy proxy allows injection of circular dependencies.
var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterLazy<IFoo, Foo>(); var container = containerBuilder.Build(); Console.WriteLine("Resolving service..."); var foo = container.Resolve<IFoo>(); Console.WriteLine("Bar execution..."); foo.Bar(); // Resolving service... // Bar execution... // Hello from ctor // Hello from Bar
This project is licensed under the Apache License, Version 2.0. - see the LICENSE file for details.