Category: Exams of ASP.NET

Project – Improved message interpreter – Behavioral Patterns

Conclusion The Chain of Responsibility pattern is another great GoF pattern. It divides a large problem into smaller, cohesive units, each doing one job: handling its specific request(s).Now, let’s see how the Chain of Responsibility pattern can help us follow the SOLID principles: Next, let’s use the Template Method and Chain of Responsibility patterns to […]

Design – Behavioral Patterns-2

Each handler does two things: Let’s use Program.cs as the consumer of the Chain of Responsibility (the Client) and use a POST requests to interface with our REST API and build the message.Here is the first part of our REST API: var builder = WebApplication.CreateBuilder(args);builder.Services.AddSingleton<IMessageHandler>(    new AlarmTriggeredHandler(        new AlarmPausedHandler(            new AlarmStoppedHandler()))); In the preceding code, […]

Implementing the Template Method pattern – Behavioral 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 two new design patterns from the well-known Gang of Four (GoF). They are behavioral patterns, meaning […]

Conclusion – Structural Patterns

The Façade pattern is handy for simplifying consumers’ lives, allowing us to hide subsystems’ implementation details behind a wall. There are multiple flavors to it; the two most prominent ones are: Now, let’s see how the transparent façade pattern can help us follow the SOLID principles: Finally, let’s see how the opaque façade pattern can […]

Flexibility in action – Structural Patterns

As discussed, the transparent façade adds more flexibility. Here, we explore this flexibility in action.Context: We want to change the behavior of the TransparentFacade class. At the moment, the result of the transparent/b endpoint looks like this: Component B, Operation CComponent B, Operation DComponent C, Operation F To demonstrate we can extend and change the […]

The program – Structural Patterns

Now, let’s analyze the consumer, an ASP.NET Core application that forwards HTTP requests to the façades and return the result as their response.The first step is to register the dependencies like this: var builder = WebApplication.CreateBuilder(args);builder.Services    .AddOpaqueFacadeSubSystem()    .AddTransparentFacadeSubSystem(); With these extension methods, the application root is so clean that it is hard to know that […]

Project – Greeter – Structural Patterns

Context: We’ve programmed a highly sophisticated greeting system that we want to reuse in a new program. However, its interface does not match the new design, and we cannot modify it because other systems use that greeting system.To fix this problem, we decided to apply the Adapter pattern. Here is the code of the external […]

Project – BookStore – Structural Patterns-3

In the preceding Create method, we create the corporation, add two stores, then return the result.The CreateTaleTowersStore and CreateEpicNexusStore methods create a store, set their name, address, and manager, and create three sections each: private IComponent CreateTaleTowersStore(){    var store = new Store(        “Tale Towers”,        “125 Enchantment Street, Storyville, SV 72845”,        “Malcolm Reynolds”    );    store.Add(CreateFantasySection());    store.Add(CreateAdventureSection());    […]

Project – BookStore – Structural Patterns-1

Context: We built a program in the past to support a bookstore. However, the store is going so well that our little program is not enough anymore. Our fictional company now owns multiple stores. They want to divide those stores into sections and manage book sets and single books. After a few minutes of gathering […]

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 […]



          Copyright © 2015-2024 | About | Terms of Service | Privacy Policy