[Gtk-sharp-list] [PROPOSAL] Eliminating Application.Init ()

Michael Poole mdpoole@troilus.org
Sat, 13 Sep 2003 23:15:52 -0400

Jonathan Pryor <jonpryor@vt.edu> writes:

> So, you want to rely on the Library to handle initialization order?
> Sorry for being bold and/or mean, but are you insane?
> The problem is that static constructors guarantee NO ORDER.  The only
> thing you can assume is that the static constructor will be invoked
> before any static members are accessed, or any types are created.
> You can't say "this .cctor should execute before this other .cctor
> (which could be located in a completely different assembly!)."

You cannot specify cross-assembly ordering of .cctors, but you can
adapt the Singleton pattern to ensure correct ordering.  Implementing
that as a CLI Attribute-type class is left as an exercise for the
reader.  It does add a line or two of code to the library's
implementation, but it saves that much code from every application.

The significant difference between this and the apartment models is
that the Init()-type functions take no arguments, but more than one
threading model is possible.  As you pointed out later in your email,
automatic initialization is appropriate only for cases where the
argument list is trivial.