public static void Init(ProfilingOptions options = null) { //store the options Options = options ?? new ProfilingOptions(); //DbProviderFactories has a private static method (thanks jetBrains decompiler!) which gives us a non copy of the available DbProviderFactories var dbProvidersFactoriesDataTable = typeof(DbProviderFactories).GetMethod("GetProviderTable", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, null) as DataTable; if(dbProvidersFactoriesDataTable == null) return; var dbProviderFactoryTypes = dbProvidersFactoriesDataTable.Rows.OfType<DataRow>().Select(x => x["InvariantName"].ToString()).ToList(); foreach (var providerInvariantName in dbProviderFactoryTypes) { var factory = DbProviderFactories.GetFactory(providerInvariantName); //this should never happen, but check if dbFactoryProvider was already added to dataset if (factory.GetType().Assembly == typeof(ProxyDbProviderFactory<>).Assembly) { continue; } OverrideDefaultFactory(factory.GetType(), providerInvariantName, dbProvidersFactoriesDataTable); } GenericProfiler = new GenericProfiler(Options); }
public GenericProfiler(ProfilingOptions implementation) { Implementation = implementation; _profileOutput = Implementation.CreateOutput(); }