| 1 | struct Test { |
| 2 | something string |
| 3 | } |
| 4 | |
| 5 | struct Dependency {} |
| 6 | |
| 7 | struct Factory { |
| 8 | build fn () ! |
| 9 | } |
| 10 | |
| 11 | fn inject[T](mut serv T) ! { |
| 12 | $for field in T.fields { |
| 13 | if field.typ is string { |
| 14 | serv.$(field.name) = 'Hello world!' |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | fn use_factory[F, E](factory fn (dep F) !E) Factory { |
| 20 | return Factory{ |
| 21 | build: fn [factory] [F]() ! { |
| 22 | mut dep := F{} |
| 23 | inject[F](mut dep)! |
| 24 | dump(factory(dep)!) |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | use_factory[Dependency, Test](fn (dep Dependency) !Test { |
| 30 | return Test{ |
| 31 | something: 'daleks!' |
| 32 | } |
| 33 | }).build()! |
| 34 | |