Skip to content

Commit ee89030

Browse files
Update readme file
1 parent 8d261c8 commit ee89030

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,57 @@ Provides a short code generator that can be used to create small user accessible
1010
- ![Nuget](https://img.shields.io/nuget/v/Stravaig.ShortCode.DependencyInjection?color=004880&label=nuget%20stable&logo=nuget) [View on NuGet](https://www.nuget.org/packages/Stravaig.ShortCode.DependencyInjection)
1111
- ![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/Stravaig.ShortCode.DependencyInjection?color=ffffff&label=nuget%20latest&logo=nuget) [View on NuGet](https://www.nuget.org/packages/Stravaig.ShortCode.DependencyInjection)
1212

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.
16+
1317
## Installing the packages
1418

19+
At the command line:
20+
```powershell
21+
> dotnet add package Stravaig.ShortCode
22+
23+
> dotnet add package Stravaig.ShortCode.DependencyInjection
24+
```
25+
26+
Or using the package manager:
27+
```powershell
28+
> Install-Package Stravaig.ShortCode
29+
30+
> Install-Package Stravaig.ShortCode.DependencyInjection
31+
```
32+
33+
You can also install using the package manager.
34+
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+
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.
40+
41+
e.g.
42+
```csharp
43+
services.AddShortCodeGenerator<GuidCodeGenerator>(options =>
44+
{
45+
options.FixedLength = 5;
46+
options.CharacterSpace = Encoder.LettersAndDigits;
47+
});
48+
```
49+
50+
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

Comments
 (0)