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
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,5 +10,57 @@ Provides a short code generator that can be used to create small user accessible
10
10
-[View on NuGet](https://www.nuget.org/packages/Stravaig.ShortCode.DependencyInjection)
11
11
-[View on NuGet](https://www.nuget.org/packages/Stravaig.ShortCode.DependencyInjection)
12
12
13
+
## Package overview
14
+
15
+
There are two packages. The `Stravaig.ShortCode` package contains the classes needed to generate short codes. The `Stravaig.ShortCode.DependencyInjection` package contains extensions for the Microsoft Dependency Injection framework that comes with .NET Core / .NET 5.0 to makes setting up in your application easier.
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
+
37
+
## Setting up Short Codes with Microsoft's Dependency Injection
38
+
39
+
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.
There are many strategies for generating codes, so you will need to specify that. The following are the current strategies that are supplied in the package:
51
+
52
+
-`GuidCodeGenerator`: The code is a hashed form of a GUID
53
+
-`RandomCodeGenerator`: The code is generated from the `Random` class.
54
+
-`SequentialCodeGenerator`: The code is a sequential increment from the previous code.
55
+
-`CrytographicallyRandomCodeGenerator`: The code is generated using a cryptographic strength random number generator.
56
+
57
+
The `options` are not required, and if missing a reasonable set of defaults will be used. If a logger is set up, a warning will be generated if the options are set up poorly but won't break.
58
+
59
+
Once set up, in your application code you need to add `IShortCodeFactory` to any class that needs to generate short codes.
60
+
61
+
## Using the IShortCodeFactory
62
+
63
+
To get a short code, the `IShortCodeFactory` interface exposes two methods for to create short codes.
64
+
65
+
*`GetNextCode()` will simply get the next code.
66
+
*`GetCodes(int)` will return the number of codes specified as an `IEnumerable<string>`
0 commit comments