Interface IIdGeneratorFactory
Interface for factory classes, which create instances of IIdGenerator.
Namespace: Kros.Data
Assembly: Kros.Utils.dll
Syntax
public interface IIdGeneratorFactory
Examples
public class PeopleService
{
private IIdGeneratorFactory _idGeneratorFactory;
public PeopleService(IIdGeneratorFactory idGeneratorFactory)
{
_idGeneratorFactory = Check.NotNull(idGeneratorFactory, nameof(idGeneratorFactory));
}
public void GenerateData()
{
using (var idGenerator = _idGeneratorFactory.GetGenerator("people", 1000))
{
for (int i = 0; i < 1800; i++)
{
var person = new Person()
{
Id = idGenerator.GetNext()
};
}
}
}
}
Methods
GetGenerator(String)
Creates an instance of IIdGenerator for table tableName
.
Declaration
IIdGenerator GetGenerator(string tableName)
Parameters
Type | Name | Description |
---|---|---|
System.String | tableName | Table for which IDs will be generated. |
Returns
Type | Description |
---|---|
IIdGenerator | The instance of IIdGenerator. |
GetGenerator(String, Int32)
Creates an instance of IIdGenerator for table tableName
with specified batchSize
.
Declaration
IIdGenerator GetGenerator(string tableName, int batchSize)
Parameters
Type | Name | Description |
---|---|---|
System.String | tableName | Table for which IDs will be generated. |
System.Int32 | batchSize | IDs batch size. This number of IDs will be reserved for later use. |
Returns
Type | Description |
---|---|
IIdGenerator | The instance of IIdGenerator. |