Skip to content

Month: November 2017

Using Lazy<T, TMetadata> in Dependency Injection

We know how to use a Lazy<T> and IEnumerable<T>. Recently, I came across a piece of code that uses these two in combination. However, it doesn’t make sense if we simply inject a dependency of IEnumerable<Lazy<T>>. Therefore, we need some data to decide which one of the registered implementations, returned by the container, shall be instantiated. This data is generally known as the Metadata. In…