-
|
I've been writing Settings result = null;
if (generators.bytes() instanceof AbstractGenerator<?> gen) {
result = gen.getContext().getSettings();
}This is quite dirty way to do it. Is there a conventional/supported way to access Settings API in this context? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
This one is bit hidden. The supported way to access public class MyServiceProvider implements InstancioServiceProvider {
private Settings settings;
@Override
public void init(ServiceProviderContext context) {
this.settings = context.getSettings();
}
@Override
public GeneratorProvider getGeneratorProvider() {
return (node, generators) -> {
// settings.get(...)
};
}
}The |
Beta Was this translation helpful? Give feedback.
This one is bit hidden. The supported way to access
Settingsis throughInstancioServiceProvider.init(ServiceProviderContext)method. TheServiceProviderContextinterface exposesgetSettings()(andrandom()if you need it for generating reproducible data).The
init()method is called oncegetGeneratorProvider()…