bchavez / bchavez/Bogus

Passing parameters to Faker

Open
#554 0 comments 0 reactions 0 assignees View on GitHub
enhancement future
Dominant language
C#
Stars
9.7k
Forks
538
PR merge metrics
No merged PRs in 30d

Description

### Description

I would like the ability to set/get `Faker` parameters for example by calling Faker.AddParameter(string, object) and Faker.GetParameter(string, object) so that it can be used in `Faker.RuleFor()` and `Faker.Rules()`.

An example on how to do this was provided in https://github.com/bchavez/Bogus/issues/460#issuecomment-1409712488 using extension methods and it would be awesome if the extension methods were officially implemented in the library as a builtin feature.

Similar features in other libraries
- Mapster https://github.com/MapsterMapper/Mapster/wiki/Setting-values#passing-run-time-value.
- FluentValidation https://docs.fluentvalidation.net/en/latest/advanced.html#root-context-data

### LINQPad Code Example

An example was provided in https://github.com/bchavez/Bogus/issues/460#issuecomment-1409712488.

### What alternatives have you considered?

- Use the extension methods documented in https://github.com/bchavez/Bogus/issues/460#issuecomment-1409712488.
- Inherit from Faker.
- Wrap Faker in a method.

### Could you help with a pull-request?

Yes, if I can spare some time

Contributor guide

Open the contributing guide

Research direction

Start with the extension-method example linked from issue #460 and compare its behavior with Faker.RuleFor() and Faker.Rules(). Identify the library entry points that would own parameter storage and access, then determine the required API and tests for setting and retrieving values during rule evaluation. Done means the supported built-in feature matches the documented runtime-value use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.