Skip to content

servicetitan/lazy-proxy-autofac

Repository files navigation

Lazy injection for Autofac container

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

License

This project is licensed under the Apache License, Version 2.0. - see the LICENSE file for details.

About

Lazy Dependency Injection for Autofac Container

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages