Auto-registration of specialized factory
<p>I have a factory that processes a custom message format. Several different message sets, based on this format, are defined in the system. I am attempting to restructure the message processing code so that message sets “auto-register” with the factory.  This will allow us to only included needed message sets in various parts of the system and also allow message sets to be added without effecting existing code.</p>

<p>The main factory class with registration is as follows.</p>

<pre><code>public class MessageFactory
{    
    internal static List&lt;FactoryListEntry&gt; _seriesFactories = new List&lt;FactoryListEntry&gt;();

    public static void RegisterSeriesFactory( long seriesId, ushort seriesVersion,
                                              ISeriesFactory factory )
    {
        MessageFactory._seriesFactories.Add( 
            new FactoryListEntry( seriesId, seriesVersion, factory ));
    }
}
</code></pre>

<p>The auto register class for a unique series looks like this.</p>

<pre><code>public class Series1AutoRegistration
{
    private static Series1AutoRegistration register = new Series1AutoRegistration();

    private Series1AutoRegistration()
    {
        MessageFactory.RegisterSeriesFactory( SERIES_ID,
                                              SERIES_VERSION,
                                              new Series1Factory() );

    }
}
</code></pre>

<p>In C++ I would have just made a global static Series1AutoRegistration variable.  However, c# does not guarantee initialization of static member until just before it is used so the auto-registration does not happen.  Does anyone have ideas on how I can accomplish this?</p>
