1 IList<string> dsNames = cfg.GetPropertyGroups(PropertyDataSourcePrefix); 2 foreach (string dataSourceName in dsNames) 3 { .FormatInvariant(PropertyDataSourcePrefix, dataSourceName); 5 NameValueCollection propertyGroup = cfg.GetPropertyGroup(datasourceKey, true); 6 PropertiesParser pp = new PropertiesParser(propertyGroup); 7 8 Type cpType = loadHelper.LoadType(pp.GetStringProperty(PropertyDbProviderType, null)); (cpType != null) 12 { 13 IDbProvider cp; { 16 cp = ObjectUtils.InstantiateType<IDbProvider>(cpType); 17 } 18 catch (Exception e) 19 { .FormatInvariant(cpType), e); 21 throw initException; 22 } { pp.UnderlyingProperties.Remove(PropertyDbProviderType); 28 29 ObjectUtils.SetObjectProperties(cp, pp.UnderlyingProperties); 30 cp.Initialize(); 31 } 32 catch (Exception e) 33 { .FormatInvariant(cpType), e); 35 throw initException; 36 } 37 38 dbMgr = DBConnectionManager.Instance; 39 dbMgr.AddConnectionProvider(dataSourceName, cp); 40 } { 43 string dsProvider = pp.GetStringProperty(PropertyDataSourceProvider, null); 44 string dsConnectionString = pp.GetStringProperty(PropertyDataSourceConnectionString, null); 45 string dsConnectionStringName = pp.GetStringProperty(PropertyDataSourceConnectionStringName, null); (dsConnectionString == null && !String.IsNullOrEmpty(dsConnectionStringName)) 48 { 49 50 ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings[dsConnectionStringName]; 51 if (connectionStringSettings == null) 52 { .FormatInvariant(dsConnectionStringName, dataSourceName)); 54 throw initException; 55 } 56 dsConnectionString = connectionStringSettings.ConnectionString; 57 } (dsProvider == null) 60 { .FormatInvariant(dataSourceName)); 62 throw initException; 63 } 64 if (dsConnectionString == null) 65 { .FormatInvariant(dataSourceName)); 67 throw initException; 68 } { 71 DbProvider dbp = new DbProvider(dsProvider, dsConnectionString); 72 dbp.Initialize(); 73 74 dbMgr = DBConnectionManager.Instance; 75 dbMgr.AddConnectionProvider(dataSourceName, dbp); 76 } 77 catch (Exception exception) 78 { .FormatInvariant(dataSourceName), exception); 80 throw initException; 81 } 82 } 83 }
接下来的问题就是这几个属性是如何配置进去的,仔细观察上面代码,你会发现所有的配置的源头都来自于cfg变量,ok,接下来你可以继续翻看代码,相信
你会看到有一个Initialize方法就是做cfg变量的初始化,如下代码所示: