You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,36 @@ You can also install using the package manager.
34
34
35
35
If you are going to be using extensions for the Microsoft Dependency Injection then you only need to install the `Straviag.ShortCode.DependencyInjection` package in your application entry assembly (the assembly in which you setup the dependency injection for your application) as it has a dependency on `Stravaig.ShortCode` already. In any other assembly in your application that needs to generate short codes, you will typically only need to install the `Stravaig.ShortCode` package.
36
36
37
+
## Fastest way to get started
38
+
39
+
There is a `static ShortCode` class that is preconfigures with some _reasonable_ defaults, although they can be overridden if desired.
40
+
41
+
To get a short code:
42
+
43
+
```csharp
44
+
// To generate a 7 character random short code
45
+
ShortCode.GenerateRandomShortCode();
46
+
47
+
// To generate short code of the given length
48
+
ShortCode.GenerateRandomShortCode(intlength);
49
+
50
+
// To generate a 7 character sequential short code
51
+
ShortCode.GenerateSequentialShortCode();
52
+
53
+
// To generate sequential short code of the given length
54
+
ShortCode.GenerateSequentialShortCode(intlength);
55
+
```
56
+
57
+
There are some configuration methods you can call during your app's startup:
58
+
59
+
*`ShortCode.SetLength(int)` sets the default length of the short codes that you want, defaults to 7.
60
+
*`ShortCode.SetSequentialSeed(ulong)` sets the starting point for the sequential codes, otherwise it will reset to zero every time your app starts.
61
+
*`ShortCode.SetCharacterSpace(string)` sets the characters that can be used in a short code, defaults to `NamedCharacterSpaces.LettersAndDigits` which is a list of unaccented Latin letters in lower and upper case and the digits zero to nine.
62
+
*`ShortCode.Use<TGenerator>()` sets the random generator to use. `TGenerator` can be:
63
+
-`GuidCodeGenerator`: The code is a hashed form of a GUID
64
+
-`RandomCodeGenerator`: The code is generated from the `Random` class.
65
+
-`CrytographicallyRandomCodeGenerator`: The code is generated using a cryptographic strength random number generator.
66
+
37
67
## Setting up Short Codes with Microsoft's Dependency Injection
38
68
39
69
If web apps this will be in your `Startup` class, somewhere in the `ConfigureServices` method. Otherwise it will go wherever you are adding your dependency to the service collection.
0 commit comments