How to register custom `DataSet`s for scoped/local seed propagation given by `UseSeed`
- Dominant language
- C#
- Stars
- 9.7k
- Forks
- 538
- PR merge metrics
- No merged PRs in 30d
Description
### Version Information
| Software | Version(s) |
| ------------------------| ---------- |
| Bogus NuGet Package | 33.1.1 |
| .NET SDK | 5.0.403 |
| Windows OS | Version 20H2 |
| Visual Studio? | Microsoft Visual Studio Enterprise 2022 (64-bit) Version 17.0.1 |
### What locale are you using with Bogus?
`en`
### What's the problem?
Hi!
I am not really sure how to make a custom `DataSet` use a `Faker` instance's configured scoped/local seed (configured via its `UseSeed(int)` option, added during [this PR](https://github.com/bchavez/Bogus/pull/101) due to [this issue](https://github.com/bchavez/Bogus/issues/100)) for generation.
If I understand correctly, this is because its `FakerHub` (of course; or only if I am missing something) cannot (seed-) notify the custom `DataSet`.
E.g. if we have a `CustomDataSet` (similarly to how it is suggested [in this example](https://github.com/bchavez/Bogus/blob/master/Examples/ExtendingBogus/FoodDataSet.cs)), then using the `this.Random` for generating does not give seeded values, because of [the randomizer never being set](https://github.com/bchavez/Bogus/blob/b093964bb895e11d051ad53eba13275ffb103e53/Source/Bogus/Faker.cs#L55).
### What possible solutions have you considered?
As I understand it, it should be possible for `Faker` derivates, because `this.Notifier` would be accessible, thus one could add
```csharp
this.CustomDataSet = this.Notifier.Flow(new CustomDataSet());
```
in there.
But this does not work for `Faker`, because the `Notifier` of its `FakerHub` is not accessible.
I have also considered explicitly passing the `Randomizer` instance to the custom dataset, but that would disable the notifier mechanism there, if I understand correctly.
### Do you have sample code to show what you're trying to do?
Not sure how to do this in a short amount of time in LinqPad.
But simply using the [`Food` dataset](https://github.com/bchavez/Bogus/blob/master/Examples/ExtendingBogus/FoodDataSet.cs) from a `Faker` instance with configured constant local seed yields different results for each test/app execution because the randomizer is never explicitly [set, thus a new `Randomizer` instance without the seed](https://github.com/bchavez/Bogus/blob/b093964bb895e11d051ad53eba13275ffb103e53/Source/Bogus/Faker.cs#L55) is created and attached to it.
Contributor guide
Research direction
Start with Source/Bogus/Faker.cs and the UseSeed, Notifier, and FakerHub paths described in the issue, then compare them with the FoodDataSet example. Trace how a custom DataSet receives its Randomizer when used through Faker. Done means a custom DataSet used through Faker produces repeatable values from the configured local seed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100