concept code block in category dependency injection

appears as: code block, code blocks, The code block
Dependency Injection

This is an excerpt from Manning's book Dependency Injection.

You can use the code block provided to the As method for every single type whose name ends with Policy. This ensures that all classes with the Policy suffix will be registered against their base class, so that when the base class is requested, the container will resolve it to the type mapped by this convention. Convention-based registration with Autofac is surprisingly easy and uses an API that closely mirrors the API exposed by the singular RegisterType method.

Instead of making the registration for IIngredient using the Auto-Wiring overload of AddTransient, you register a code block that, when called, forwards the call to the registration of the concrete SauceBéarnaise.

Dependency Injection in .NET

This is an excerpt from Manning's book Dependency Injection in .NET.

4 Technically, it isn’t a lambda expression but rather a code block. Most .NET developers know such code constructs as lambda expressions, so I chose the more well-known term over the more correct one.

The Configure method provides the opportunity to configure a ConfigurationExpression using a code block (see the following sidebar “Nested Closures” for an explanation). The configuration statement reads almost like a sentence (or like instructions from a cookbook): for IIngredient use SauceBéarnaise. The For method enables you to define the ABSTRACTION while the Use method lets you define the concrete type that implements the ABSTRACTION.

By now, the For/Use method chain should be familiar. However, in this variation, you use a different overload of the Use method than used previously. This overload enables you to supply a Func<IMeal> and you do that by providing a code block that invokes the static Create method on the JunkFoodFactory class.