Class IdGeneratorFactories
Helper class for ID generator factories (IIdGeneratorFactory) for different databases. Factories are registered in the class using Register<TConnection>(String, Func<DbConnection, IIdGeneratorFactory>, Func<String, IIdGeneratorFactory>) method. Two factory methods are registered for every connection (database) type. One for creating generator with connection instance and one with connection string.
Inheritance
Namespace: Kros.Data
Assembly: Kros.Utils.dll
Syntax
public static class IdGeneratorFactories
Remarks
SqlServerIdGeneratorFactory is automatically registered.
Methods
GetFactory(DbConnection)
Returns IIdGeneratorFactory for specified connection
.
Declaration
public static IIdGeneratorFactory GetFactory(DbConnection connection)
Parameters
Type | Name | Description |
---|---|---|
System.Data.Common.DbConnection | connection | Database connection. |
Returns
Type | Description |
---|---|
IIdGeneratorFactory | Instance of IIdGeneratorFactory. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Factory for type of |
GetFactory(String, String)
Returns IIdGeneratorFactory for specified connectionString
and database
type adoClientName
.
Declaration
public static IIdGeneratorFactory GetFactory(string connectionString, string adoClientName)
Parameters
Type | Name | Description |
---|---|---|
System.String | connectionString | Connection string for database. |
System.String | adoClientName | Name, which specifies database type. |
Returns
Type | Description |
---|---|
IIdGeneratorFactory | Instance of IIdGeneratorFactory. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Factory for database type specified by |
Register<TConnection>(String, Func<DbConnection, IIdGeneratorFactory>, Func<String, IIdGeneratorFactory>)
Registers ID generator factory methods factoryByConnection
and
factoryByConnectionString
for database specified by connection type
TConnection
and client name adoClientName
.
Declaration
public static void Register<TConnection>(string adoClientName, Func<DbConnection, IIdGeneratorFactory> factoryByConnection, Func<string, IIdGeneratorFactory> factoryByConnectionString)
where TConnection : DbConnection
Parameters
Type | Name | Description |
---|---|---|
System.String | adoClientName | Name of the database client. It identifies specific database. For example client name for SqlServerIdGeneratorFactory is "System.Data.SqlClient" (ClientId). |
System.Func<System.Data.Common.DbConnection, IIdGeneratorFactory> | factoryByConnection | Factory method for creating IIdGeneratorFactory with connection instance. |
System.Func<System.String, IIdGeneratorFactory> | factoryByConnectionString | Factory method for creating IIdGeneratorFactory with connection string. |
Type Parameters
Name | Description |
---|---|
TConnection | Database connection type. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Value of any argument is null. |
System.ArgumentException | Value of |