The Decorator pattern is one of our toolbox’s simplest yet most powerful design patterns. It augments existing classes without modifying them. A decorator is an independent block of logic that we can use to create complex and granular object trees that fit our needs.We also explored the Scrutor open-source library to assist us in registering […]
DecoratorB – Structural Patterns-2
In the preceding code, we registered ComponentA as the implementation of IComponent, with a singleton lifetime, just like the first time.Then, by using Scrutor, we told the IoC container to override that first binding and to decorate the already registered IComponent (ComponentA) with an instance of DecoratorA instead. Then, we overrode the second binding by […]
DecoratorB – Structural Patterns-1
Now that we have a decorator, it is time to create a second decorator to demonstrate the power of chaining decorators.Context: we need another content wrapper but don’t want to modify existing classes. To achieve this, we concluded that creating a second decorator would be perfect, so we created the following DecoratorB class: public class […]
Project – Adding behaviors – Structural Patterns
Let’s implement the previous example to help visualize the Decorator pattern, which adds some arbitrary behaviors. Each Operation() method returns a string that is then outputted to the response stream. It is not fancy but visually shows how the pattern works.First, let’s look at the IComponent interface: public interface IComponent{ string Operation();} The IComponent interface […]
Design – Structural Patterns
A decorator class must implement and use the interface the decorated class implements. Let’s see this step by step, starting with a non-decorated class design: Figure 11.1: A class diagram representing the ComponentA class implementing the IComponent interface In the preceding diagram, we have the following components: This translates into the following sequence diagram: Figure […]
Implementing the Decorator design pattern – Structural Patterns
Before you begin: Join our book community on Discord Give your feedback straight to the author himself and chat to other early readers on our Discord server (find the “architecting-aspnet-core-apps-3e” channel under EARLY ACCESS SUBSCRIPTION). https://packt.link/EarlyAccess This chapter explores four design patterns from the well-known Gang of Four (GoF). We use Structural patterns to build […]
Structured logging – Logging patterns
As stated at the beginning, structured logging can become very important and open opportunities. Querying a data structure is always more versatile than querying a single line of text. That is even more true if there is no clear guideline around logging, whether a line of text or a JSON-formatted data structure.To keep it simple, […]
Logging providers – Logging patterns
To give you an idea of the possible built-in logging providers, here is a list from the official documentation (see the Further reading section at the end of this chapter): The following is a list of third-party logging providers, also from the official documentation: Now, if you need any of those or your favorite logging […]