Category: Using the implementations

IOptionsFactory – Options, Settings, and Configuration

This interface is a factory, as we saw in Chapter 7, Strategy, Abstract Factory, and Singleton, and in Chapter 8, Dependency Injection, we use factories to create instances; this interface is no different. Unless necessary, I suggest sticking with IOptionsMonitor<TOptions> or IOptionsSnapshot<TOptions> instead. How the factory works is simple: the container creates a new factory […]

Loading the configuration – Options, Settings, and Configuration

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 covers the .NET Options pattern, a building block of any application. .NET Core introduced new predefined mechanisms […]

Summary – Dependency Injection

This chapter delved into Dependency Injection, understanding its crucial role in crafting adaptable systems. We learned how DI applies the Inversion of Control principle, shifting dependency creation from the objects to the composition root. We explored the IoC container’s role in object management, service resolution and injection, and dependency lifetime management. We tackled the Control […]

Project – Wishlist – Dependency Injection-2

That code leverages the new API, but we’ll stick to our simple implementation instead. Let’s look at the outline of the unit tests next because the whole code would take pages and be of low value: namespace Wishlist;public class InMemoryWishListTest{    // Constructor and private fields omitted    public class AddOrRefreshAsync : InMemoryWishListTest    {        [Fact]        public async […]

Project – Wishlist – Dependency Injection-1

Let’s get into another sample to illustrate using the singleton lifetime and DI. Seeing DI in action should help understand it and then leverage it to create SOLID software.Context: The application is a site-wide wishlist where users can add items. Items expire every 30 seconds. When a user adds an existing item, the system must […]

Using the implementations – Dependency Injection

We can now use any of the two implementations without impacting the rest of the program. That demonstrates the strength of DI when it comes to dependency management. Moreover, we control the lifetime of the dependencies from the composition root.If we were to use the IApplicationState interface in another class, say SomeConsumer, its usage could […]

First implementation – Dependency Injection

The first implementation uses the memory cache system, and I thought it would be educational to show that to you. Caching data in memory is something you might need to do sooner rather than later. However, we are hiding the cache system behind our implementation, which is also educational.Here is the ApplicationMemoryCache class: public class […]

Revisiting the Singleton pattern – Dependency Injection

The Singleton pattern is obsolete, goes against the SOLID principles, and we replace it with a lifetime, as we’ve already seen. This section explores that lifetime and recreates the good old application state, which is nothing more than a singleton-scoped dictionary.We explore two examples: one about the application state, in case you were wondering where […]



         


          Terms of Use | Accessibility Privacy