August 2018
Beginner
594 pages
22h 33m
English
One approach to handling cross-cutting concerns is to use the DI pattern, which we covered in Chapter 6, Software Development Principles and Practices. This pattern can be used to inject cross-cutting dependencies into classes that need them. This allows us to write loosely coupled code and avoid scattering. The logic for the cross-cutting concern will not be duplicated in multiple places.
For example, if we had an Order class that had logging and caching cross-cutting concerns, we could inject them like this:
public class Order{ private readonly ILogger _logger; private readonly ICache _cache; public Order(ILogger logger, ICache cache) { if (logger == null) throw new ArgumentNullException(nameof(logger)); ...