mh-cbon / service-finder

Register a concrete service, then locate it by an interface or its concrete type

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Service finder

GoDoc

Register a concrete service, then locate it by an interface or its concrete type.

Install

go get github.com/mh-cbon/service-finder
glide install github.com/mh-cbon/service-finder

Example

package main

import (
  "fmt"
  "github.com/mh-cbon/service-finder"
)

type Doer interface {
  Do()
}
type ConcreteDo struct {}
func (c *ConcreteDo) Do() {
  fmt.Println("Did something")
}

// Example_main demonstrates usage of servicefinder package.
func main() {

    finder := servicefinder.New()

    finder.Register(&ConcreteDo{})

    var concrete *ConcreteDo
    finder.MustGet(&concrete)
    concrete.Do()

    var intface Doer
    finder.MustGet(&intface)
    intface.Do()

}

About

Register a concrete service, then locate it by an interface or its concrete type

License:MIT License


Languages

Language:Go 100.0%