Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dombrovsky authored Jun 22, 2024
1 parent 5490510 commit dd6cdf4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@ partial class FooId : IEquatable<FooId>, IComparable<FooId>, IFormattable
```

## Design decisions
There are a few opinionated principles regarding what strong type identifiers should and should not do, which may be different from similar libraries and are reasons this project exist.
There are a few opinionated principles regarding what strong type identifiers should and should not do, which may be different from similar libraries and are reasons this project existence.
#### Idenifier type should be a reference type, not a value type.
Being able to protect invariants and not allow instance of id with invalid value to exist, is chosen over avoiding additional object allocation.
#### No dependency on serialization libraries.
StrongTypeIdGenerator only defines `System.ComponentModel.TypeConverter` that can convert to and from `string`. No `System.Text.Json` or `Newtonsoft.Json` or EF Core converters defined.

This way Id types can be defined in `netstandard2.0` libraries with no additional dependencies.

The proposed way to use generated Id classes in serialization e.g. with `System.Text.Json` is to provide [custom JsonConverterFactory](https://github.com/dombrovsky/StrongTypeIdGenerator/blob/main/StrongTypeIdGenerator.Json/TypeConverterJsonConverterFactory.cs) to serializer, that would utilize generated `TypeConverter`.
#### Ability to define custom id precondition checks.
If Id class defines method `static void CheckValue(string value)`, what method would be called from generated constructor.
If Id class defines method `static void CheckValue(string value)`, that method would be called from generated constructor.
```csharp
[StringId]
partial class FooId
Expand All @@ -93,10 +97,6 @@ partial class FooId
}
```

This way Id types can be defined in `netstandard2.0` libraries with no additional dependencies.

The proposed way to use generated Id classes in serialization e.g. with `System.Text.Json` is to provide [custom JsonConverterFactory](https://github.com/dombrovsky/StrongTypeIdGenerator/blob/main/StrongTypeIdGenerator.Json/TypeConverterJsonConverterFactory.cs) to serializer, that would utilize generated `TypeConverter`.

## Installation
Add nuget package https://www.nuget.org/packages/StrongTypeIdGenerator. Make sure to specify `PrivateAssets="all"`:
```
Expand Down

0 comments on commit dd6cdf4

Please sign in to comment.