Recognos/Metrics.NET

Circular dependencies in static constructors

Opened this issue · 0 comments

There are some circular dependencies between static fields.
For example, MetricsErrorHandler creates global error meter using static members of Metric class and static field initializers of Metric class handle exceptions by passing them to MetricsErrorHandler.

Moreover, the class MetricsErrorHandler doesn't have an explicit static constructor, so compiler marks it with beforefieldsinit flag. This flag allows the JIT compiler to run its type initializer before any fields of this class are referenced, adding, even more, complexity to the initialization order.

  1. There are too many things happening inside static field initializers. Encapsulating the into singletons seems to be a reasonable solution, to simplify the initialization process.
  2. Consider adding an explicit static constructor (possibly empty) to classes with static fields, making the initialization more predictable.