Dependency Injection from config file

Written by
Link to Post by 

I’ve been reading around a bit about Dependency Injection in Go tonight, and especially about wire, which does it by code generation.

What I’ve not seen is anything that does it from a config file instead of from Go code. This is surprising to me since, from my Java background, I’m most used to DI using Spring, which itself was traditionally powered by XML files.

I’m envisioning something like this:

{ "database": { "package": "", "factory": "New" }, "userRepository": { "package": "", "factory": "NewUserRepository", "parameters": [ {"type": "bean", "ref": "database"} ] }, "userHandler": { "package": "", "factory": "NewUserHandler", "parameters": [ {"type": "bean", "ref": "userRepository" ] } } 

This could then generate appropriate Go code to:

I’ve no idea how to do this – yet – but it doesn’t seem unreasonable to me, and possibly a lot cleaner than some of the options that I’ve seen.

Does this seem completely crazy? Or has this already been done somewhere?

submitted by /u/sazzer
[link] [comments]

Article Tags:
· ·
Article Categories:

Leave a Reply