GoDoc | http://godoc.org/github.com/ParsePlatform/go.inject |
Code | https://github.com/ParsePlatform/go.inject |
License | Apache License, Version 2.0 |
This library has been created, and open sourced by the guys over at Parse, a provider of a cloud based backend system designed for mobile development, and a major contributor to the open source community.
The style of dependency injection that go.inject uses is reflection
Example
The example below is based on the same imaginary car sales system as used in the previous posts. The idea is that when ordering a car the request must go to a car factory that builds that particular model.
The code is broken down into it's three key areas, these being the interfaces, the concrete implementations, and a method that defines the mapping of the objects and later uses those objects to get details of the car that has been 'built'.
As with the previous post a quick look at the code, and the main function, and it should be obvious that if you wanted to substitute the make and model of car, you can change the object mapped in the graph. One key downside to this package is that it's not as flexible as the two previous packages and to truely achieve the functionality of the other examples a larger level of refactoring would be required.
The code is broken down into it's three key areas, these being the interfaces, the concrete implementations, and a method that defines the mapping of the objects and later uses those objects to get details of the car that has been 'built'.
As with the previous post a quick look at the code, and the main function, and it should be obvious that if you wanted to substitute the make and model of car, you can change the object mapped in the graph. One key downside to this package is that it's not as flexible as the two previous packages and to truely achieve the functionality of the other examples a larger level of refactoring would be required.
Loading ....
Summary
In summary, the go.inject example above does provide an option for DIP, but it is neither straightforward, or perfect. As before we would ideally want to setup object mappings at runtime and not build time, in the case of go.inject, achieving this is a not inconsiderable task, and with other options out there I don't see a reason for extending this library to include a configurable approach.
As for a recommendation, my personal view is that there are better options out there.
<< Previous: go-inject Next: depinject >>
As for a recommendation, my personal view is that there are better options out there.
<< Previous: go-inject Next: depinject >>
Links
Dependency Inversion in Go - IntroductionDependency Inversion in Go - Simple IoC
Dependency Inversion in Go - go-inject
Dependency Inversion in Go - go.inject
Dependency Inversion in Go - depinject
Dependency Inversion in Go - Summary
No comments:
Post a Comment