Open
Description
When you call a *Func()
mod like IDFunc()
, it'd be nice to know if the caller is a Build()
, BuildMany()
, BuildSetter()
or BuildManySetter()
. I think the straightforward way to do this would be to pass in an enum, like FactoryType
:
type FactoryType int
const (
FactoryBuild = iota
FactoryBuildMany
...
)
and then the *Func
functions become: *Func(func(FactoryType) T)
, e.g. IDFunc(func(FactoryType) int32)
There's at least 2 scenarios this could be useful for:
- In the case of Manys, you'd be able to create sequences, like incremented IDs (you'd have to track the index outside of the function, but I think generally for unit testing, you'd want to keep that at the test level anyway for use in assertions).
- For nested models where the you need to create the child in the middle of a service function, there's currently no way to have the ID unset for
BuildSetter()
but have it set to a non-0 value when you callBuild()
without having to create the object, store it, then modify it, which feels like it defeats the purpose of having a factory.
Edit: I goofed midway down and said Build when I meant Func, sorry!