Skip to content

Commit

Permalink
document singleton pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr committed Jun 14, 2024
1 parent 26ddde8 commit 01e3617
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,29 @@ And the output will be:
}
```

You can create a singleton provider like so:

```js
class DnsimpleProvider {
pub static getOrCreate(scope: std.IResource): tf.Provider {
let root = nodeof(scope).root;
let singletonKey = "WingDnsimpleProvider";
let existing = root.node.tryFindChild(singletonKey);
if existing? {
return unsafeCast(existing);
}

return new tf.Provider(
name: "dnsimple",
source: "dnsimple/dnsimple",
version: "1.6.0",
) as singletonKey in root;
}
}
```
Use `DnsimpleProvider.getOrCreate(scope)` to get the provider instance.
## Maintainers
* [Elad Ben-Israel](@eladb)
Expand Down

0 comments on commit 01e3617

Please sign in to comment.