Base implementation setup & creating new reference number providers - smbc-digital/form-builder GitHub Wiki

Basic Reference Number Provider Implementation Setup

Formbuilder comes with a basic reference number generator form_builder.Providers.ReferenceNumbers.ReferenceNumberProvider. It's based roughly on the code in the accepted answer on this stackoverflow post.

The intention is to keep the chances of potential reference duplication high while maintain ease of reading and reasonable length.

You can specify the characters to be used for reference generation in appsettings.config in the ValidReferenceCharacters option the default is below.

"ValidReferenceCharacters": "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

Assuming 8 random characters, this gives 218,340,105584896 (over 218 trillion) possible combinations, this can be increased by either, adding more valid reference characters or increasing the number of characters used in a reference number.

Implementing a new reference number provider

A new implementation which could use for example other more complex algothims, external providers or database driven reference numbers can be created by implementing the IReferenceNumberProvider interface, this only has a single method string GetReference(string prefix, int length).

Register this in the application startup.

services.AddTransient<IReferenceNumberProvider, MyNewReferenceNumberProvider>();

Formbuilder only currently supports a single universal reference number provider per implementation of the app.