Code Monkey home page Code Monkey logo

uber-fx-demo's Introduction

Uber Fx by example

Testing several ways to use dependency injection with fx by creating a small app that consumes a simple API that returns a random user's data and prints it at the console.

There is a folder for each approach of using dependency injection with uber fx:

v1

The Golang's vanilla way of injecting the dependencies, by using func init() in the main.go file to instantiate the needed object and then passing it to the struct.

To run this version:

$ cd v1
$ go build -o v1
$ ./v1

v2

The way that i find the simplest of using uber-fx. Using fx.Provide, we can provide the constructor that instantiates the struct we need to inject.

To run this version:

$ cd v2
$ go build -o v2
$ ./v2

v3

Still using fx.Provide, but this time adding the use of fx.In and param objects. More details here

To run this version:

$ cd v3
$ go build -o v3
$ ./v3

v4

Mapping a struct to an interface, using fx.Annotate, as seen here

To run this version:

$ cd v4
$ go build -o v4
$ ./v4

v5

Using result objects to define what you intend to inject using fx.Out.

To run this version:

$ cd v4
$ go build -o v4
$ ./v4

Those are just some of the ways i found of using Uber Fx to make my life simple. But i surely will keep finding new ways and intend to keep this repo updated with all the new stuff i stumble upon.

uber-fx-demo's People

Contributors

supwr avatar

Stargazers

Menjanahary avatar Santorato avatar

Watchers

 avatar Menjanahary avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.