Illustrates a dependency injection composition setup for invoice generation, showing how different invoice generator implementations and logging are wired
---
config:
class:
hideEmptyMembersBox: true
---
classDiagram
PdfInvoiceGenerator --|> IInvoiceGenerator
HtmlInvoiceGenerator --|> IInvoiceGenerator : "Online"
FileLogger --|> ILogger
Composition ..> LightweightRoot : LightweightRoot LightRoot
Composition ..> HtmlInvoiceGenerator : IInvoiceGenerator OnlineInvoiceGenerator
Composition ..> FileLogger : ILogger Root1
Composition ..> PdfInvoiceGenerator : IInvoiceGenerator InvoiceGenerator
PdfInvoiceGenerator *-- FileLogger : ILogger
LightweightRoot o-- "PerBlock" FuncᐸILoggerᐳ : FuncᐸILoggerᐳ
FuncᐸILoggerᐳ *-- FileLogger : ILogger
namespace Pure.DI {
class LightweightRoot {
<<class>>
+LightweightRoot()
+FuncᐸILoggerᐳ ILogger2
}
}
namespace Pure.DI.UsageTests.Basics.CompositionRootsScenario {
class Composition {
<<partial>>
+IInvoiceGenerator InvoiceGenerator
-LightweightRoot LightRoot
+IInvoiceGenerator OnlineInvoiceGenerator
-ILogger Root1
+ T ResolveᐸTᐳ()
+ T ResolveᐸTᐳ(object? tag)
+ object Resolve(Type type)
+ object Resolve(Type type, object? tag)
}
class FileLogger {
<<class>>
+FileLogger()
}
class HtmlInvoiceGenerator {
<<class>>
+HtmlInvoiceGenerator()
}
class IInvoiceGenerator {
<<interface>>
}
class ILogger {
<<interface>>
}
class PdfInvoiceGenerator {
<<class>>
+PdfInvoiceGenerator(ILogger logger)
}
}
namespace System {
class FuncᐸILoggerᐳ {
<<delegate>>
}
}
This diagram illustrates a dependency injection (DI) composition for an invoice generation system. It shows interfaces like IInvoiceGenerator and ILogger, their concrete implementations (PdfInvoiceGenerator, HtmlInvoiceGenerator, FileLogger), and how a central Composition class (acting as a DI container) wires these components together. It also demonstrates how different implementations of IInvoiceGenerator are resolved and how logging dependencies are managed, including a lazy or scoped Func<ILogger> dependency.
Use this diagram when designing or documenting the dependency graph of an application, especially when using a DI container. It's useful for visualizing how services are composed, how interfaces are implemented by multiple classes, and how dependencies are injected. Ideal for understanding the composition root of a modular application.
This diagram can be adapted by adding more invoice generation methods (e.g., EmailInvoiceGenerator), introducing different logging providers (e.g., DatabaseLogger, CloudLogger), or expanding with other services and their dependencies. You can also illustrate different DI scopes (e.g., singleton, transient, scoped) or integrate with external APIs by adding new service interfaces and implementations.