IInventoryReadContext

The IInventoryReadContext interface contains the operation to read the books, while IInventoryWriteContext contains the operations that modify the collection of books. The original IInventoryContext interface was created for convenience for when a class requires both dependency types.

In later chapters, we will cover patterns that take advantage of splitting the context, including the Command and Query Responsibility Segregation (CQRS) pattern.

With this refactor, some changes are required. First classes only requiring to read the collection of books have their constructor updated with the IInventoryReadContext interface, as illustrated in the GetInventoryCommand class:

internal class GetInventoryCommand : NonTerminatingCommand
{
private readonly IInventoryReadContext _context;
internal GetInventoryCommand(IUserInterface userInterface, IInventoryReadContext context) : base(userInterface)
{
_context = context;
}

protected override bool InternalCommand()
{
foreach (var book in _context.GetBooks())
{
Interface.WriteMessage($"{book.Name,-30} Quantity:{book.Quantity}");
}

return true;
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.131.238