Skip to content

Loading…

Optional, parameterized DbProviderFactory to DynamicModel #32

Closed
wants to merge 3 commits into from

2 participants

@slpsys

This came up while I was playing around on a VM that had access to a DbProviderFactory-inheriting assembly, but didn't have it registered with machine.config/installed in the GAC, and figured it might be useful to [optionally] allow a provider factory instance to be passed in directly. And being a trivial change, it's LOC-netural!

@robconery
Collaborator

I need the factory to be created internally - but I've since changed things so you can pass a connection. Passing a factory is a bit funky...

@robconery robconery closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 4, 2011
  1. @slpsys

    Parameterizing the DbProviderFactory; passing in the provider instanc…

    slpsys committed
    …e may be easier for ops than requiring it to be GACed everywhere.
Commits on Apr 5, 2011
  1. @slpsys

    I mean, like, LOC, right?

    slpsys committed
  2. @slpsys
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 Massive.cs
View
6 Massive.cs
@@ -94,7 +94,7 @@ public class DynamicModel {
DbProviderFactory _factory;
string _connectionString;
- public DynamicModel(string connectionStringName = "", string tableName = "", string primaryKeyField = "") {
+ public DynamicModel(string connectionStringName = "", string tableName = "", string primaryKeyField = "", DbProviderFactory providerFactory = null) {
TableName = tableName == "" ? this.GetType().Name : tableName;
PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "ID" : primaryKeyField;
if (connectionStringName == "")
@@ -106,7 +106,7 @@ public class DynamicModel {
} else {
throw new InvalidOperationException("Can't find a connection string with the name '" + connectionStringName + "'");
}
- _factory = DbProviderFactories.GetFactory(_providerName);
+ _factory = providerFactory == null ? DbProviderFactories.GetFactory(_providerName) : providerFactory;
_connectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
}
/// <summary>
@@ -364,4 +364,4 @@ public class DynamicModel {
return items.FirstOrDefault();
}
}
-}
+}
Something went wrong with that request. Please try again.