Initial: AI code exploration exercise
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
namespace Before;
|
||||
|
||||
/// <summary>
|
||||
/// The consuming application. In the "before" situation it talks to the
|
||||
/// DB-backed domain model directly: its methods take <see cref="Client"/> and
|
||||
/// <see cref="Order"/> (which inherit <see cref="DbBase"/>) as parameters.
|
||||
///
|
||||
/// One of its methods reaches the <see cref="DbContext"/> *through* a domain
|
||||
/// object — the leak. In the "after" situation (Yak 02) the WebApp consumes
|
||||
/// DTOs instead, and the domain objects no longer expose a DbContext.
|
||||
/// </summary>
|
||||
public class WebApp
|
||||
{
|
||||
/// <summary>
|
||||
/// Render a client together with all of its orders, consuming the
|
||||
/// <see cref="Client"/>/ <see cref="Order"/> domain objects directly.
|
||||
/// </summary>
|
||||
public string ShowClient(Client client)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(client);
|
||||
|
||||
var lines = new List<string> { $"{client.Name} [{client.Id}]" };
|
||||
foreach (var order in client.Orders)
|
||||
lines.Add($" - order [{order.Id}]: {order.Description}");
|
||||
return string.Join(Environment.NewLine, lines);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The leak, made concrete: from a plain domain object the WebApp can reach
|
||||
/// the <see cref="DbContext"/> (<see cref="DbBase.DbContext"/>) and thus
|
||||
/// touch the persistence layer — here just to ask whether the client has
|
||||
/// been saved. The "after" situation removes <c>client.DbContext</c>
|
||||
/// entirely, so no DTO-consumer can do this.
|
||||
/// </summary>
|
||||
public bool IsPersisted(Client client)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(client);
|
||||
return client.DbContext is not null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user