/// <summary> /// Enables the DataRepository to programatically create and /// pass in a <c>NetTiersProvider</c> during runtime. /// </summary> /// <param name="provider">An instatiated NetTiersProvider.</param> /// <param name="setAsDefault">ability to set any valid provider as the default provider for the DataRepository.</param> public static void LoadProvider(NetTiersProvider provider, bool setAsDefault) { if (provider == null) throw new ArgumentNullException("provider"); if (_providers == null) { lock(SyncRoot) { if (_providers == null) _providers = new NetTiersProviderCollection(); } } if (_providers[provider.Name] == null) { lock (_providers.SyncRoot) { _providers.Add(provider); } } if (_provider == null || setAsDefault) { lock (SyncRoot) { if(_provider == null || setAsDefault) _provider = provider; } } }
///<summary> /// Configuration based provider loading, will load the providers on first call. ///</summary> private static void LoadProviders() { // Avoid claiming lock if providers are already loaded if (_provider == null) { lock (SyncRoot) { // Do this again to make sure _provider is still null if (_provider == null) { // Load registered providers and point _provider to the default provider _providers = new NetTiersProviderCollection(); ProvidersHelper.InstantiateProviders(NetTiersSection.Providers, _providers, typeof(NetTiersProvider)); _provider = _providers[NetTiersSection.DefaultProvider]; if (_provider == null) { throw new ProviderException("Unable to load default NetTiersProvider"); } } } } }
/// <summary> /// Instantiates the configured providers based on the supplied connection string. /// </summary> private void LoadProviders() { DataRepository.LoadProviders(); // Avoid claiming lock if providers are already loaded if ( _providers == null ) { lock ( SyncRoot ) { // Do this again to make sure _provider is still null if ( _providers == null ) { // apply connection information to each provider for ( int i = 0; i < NetTiersSection.Providers.Count; i++ ) { NetTiersSection.Providers[i].Parameters["connectionStringName"] = _connectionStringName; // remove previous connection string, if any NetTiersSection.Providers[i].Parameters.Remove("connectionString"); if ( !String.IsNullOrEmpty(_connectionString) ) { NetTiersSection.Providers[i].Parameters["connectionString"] = _connectionString; } } // Load registered providers and point _provider to the default provider _providers = new NetTiersProviderCollection(); ProvidersHelper.InstantiateProviders(NetTiersSection.Providers, _providers, typeof(NetTiersProvider)); _provider = _providers[NetTiersSection.DefaultProvider]; } } } }