Skip to content

Issue #16: Temporal Coupling in Initialization #16

@shadyashraf174

Description

@shadyashraf174

Issue #16: Temporal Coupling in Initialization

Location: Program.cs
Type: Temporal Coupling
Problem:

var context = new MyDbContext(...);
InitializeData(context); // Must be called immediately after creation

Why Bad:

  • Hidden dependency between construction and initialization
  • Easy to forget the initialization step
  • Causes null reference exceptions

Solution:

public class SeededDbContext : MyDbContext 
{
    public SeededDbContext(ILoggerFactory factory) : base(factory) 
    {
        this.SeedTestData();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions