DI engine for Go

491 views
Skip to first unread message

tholowka

unread,
Feb 27, 2015, 6:30:15 PM2/27/15
to golan...@googlegroups.com
Hello All, 

I have created a small library for providing Dependency Injection in Go. 
Contrary to the other one I saw (https://github.com/facebookgo/inject) the library I've created does not rely on 'annotations' (reminiscent of the encoding/json package). 
It has its own convention and best-practices, which I tried highlighting in the Github README. 

The link to the library is https://github.com/tholowka/octopus.

My personal belief is that to make a product good, the good way is to open source it and have other people, review, test and hammer out bugs. 
If you are interested in this, please drop me a line. I will help you set this up for you if you bump into problems. 

I would appreciate suggestions whether there are bugs, and how to improve the documentation. 
Regards, 
tholowka


Egon

unread,
Feb 28, 2015, 7:02:05 AM2/28/15
to golan...@googlegroups.com
I don't understanding what problem this is actually solving.

Taking the example here's one way to write it: http://play.golang.org/p/jQU4x5yKkk
It's much simpler to understand.

Of course there are more ways to write it. e.g. http://play.golang.org/p/1Y2_wxcqQX

+ Egon

tholowka

unread,
Mar 1, 2015, 1:26:29 PM3/1/15
to golan...@googlegroups.com
Thank you

I have updated the documentation. I hope it is clearer now.

Egon

unread,
Mar 1, 2015, 2:43:32 PM3/1/15
to golan...@googlegroups.com
On Sunday, 1 March 2015 20:26:29 UTC+2, tholowka wrote:
Thank you

I have updated the documentation. I hope it is clearer now.

Sorry, initially I was looking at the wrong link - but the comments still applied to both. :)

One of the problems with DI is that it will make the dependencies less obvious leading to more complicated designs. Regarding the Go example you can write it as:

// some package xxx
var NewHTTPHandler func()http.Handler 

// some package yyy or main
func init(){
xxx.NewHTTPHandler = func() http.Handler {
return &CustomHandler{... dependencies ...}
}
}

// some package zzz
handler := xxx.NewHTTPHandler()

It has similar properties as the DI code and is more idiomatic to Go. The only main difference is that you are not providing the dependencies from JSON - which might be good or bad, depending how you look at it.

+ Egon

tholowka

unread,
Mar 2, 2015, 11:47:06 AM3/2/15
to golan...@googlegroups.com
Thank you Egon

I will update the documentation shortly. This is a very interesting example. 




thwd

unread,
Mar 2, 2015, 1:25:22 PM3/2/15
to golan...@googlegroups.com

tholowka

unread,
Mar 2, 2015, 5:21:54 PM3/2/15
to golan...@googlegroups.com
Yes, thank you for both comments. 
I was not familiar with the package approach shown very well by Egon. I did see it one example, with testing, but 
with the approach Egon proposed it actually makes my library redundant. Thank you for making me see this. 
Cheers. 
Reply all
Reply to author
Forward
0 new messages