Ejemplo n.º 1
0
func ExampleNewAliasType() {
	container := goldi.NewContainer(goldi.NewTypeRegistry(), map[string]interface{}{})

	container.Register("logger", goldi.NewStructType(SimpleLogger{}))
	container.Register("default_logger", goldi.NewAliasType("logger"))
	container.Register("logging_func", goldi.NewAliasType("logger::DoStuff"))

	fmt.Printf("logger:         %T\n", container.MustGet("logger"))
	fmt.Printf("default_logger: %T\n", container.MustGet("default_logger"))
	fmt.Printf("logging_func:   %T\n", container.MustGet("logging_func"))
	// Output:
	// logger:         *goldi_test.SimpleLogger
	// default_logger: *goldi_test.SimpleLogger
	// logging_func:   func(string) string
}
Ejemplo n.º 2
0
// RegisterTypes registers all types that have been defined in the file "types.yml"
//
// DO NOT EDIT THIS FILE: it has been generated by goldigen v0.9.9.
// It is however good practice to put this file under version control.
// See https://github.com/fgrosse/goldi for what is going on here.
func RegisterTypes(types goldi.TypeRegistry) {
	types.RegisterAll(map[string]goldi.TypeFactory{
		"kernel.http_handler":  goldi.NewAliasType("servo.routing.router::ServeHTTP"),
		"servo.routing.loader": goldi.NewStructType(new(Loader)),
		"servo.routing.router": goldi.NewType(NewRouter, "@servo.routing.loader", "@container"),
	})
}
Ejemplo n.º 3
0
// RegisterTypes registers all types that have been defined in the file "types.yml"
//
// DO NOT EDIT THIS FILE: it has been generated by goldigen v0.9.9.
// It is however good practice to put this file under version control.
// See https://github.com/fgrosse/goldi for what is going on here.
func RegisterTypes(types goldi.TypeRegistry) {
	types.RegisterAll(map[string]goldi.TypeFactory{
		"logger_provider":    goldi.NewAliasType("logxi.logger_provider"),
		"logxi.configurator": goldi.NewType(NewLoggerConfigurator, "%logxi.level%"),
		"logxi.logger_provider": goldi.NewConfiguredType(
			goldi.NewStructType(new(LoggerProvider)),
			"logxi.configurator", "Configure",
		),
	})
}
Ejemplo n.º 4
0
	fmt.Printf("logger:         %T\n", container.MustGet("logger"))
	fmt.Printf("default_logger: %T\n", container.MustGet("default_logger"))
	fmt.Printf("logging_func:   %T\n", container.MustGet("logging_func"))
	// Output:
	// logger:         *goldi_test.SimpleLogger
	// default_logger: *goldi_test.SimpleLogger
	// logging_func:   func(string) string
}

// ExampleNewAliasType_ prevents godoc from printing the whole content of this file as example
func ExampleNewAliasType_() {}

var _ = Describe("aliasType", func() {
	It("should implement the TypeFactory interface", func() {
		var factory goldi.TypeFactory
		factory = goldi.NewAliasType("foo")
		// if this compiles the test passes (next expectation only to make compiler happy)
		Expect(factory).NotTo(BeNil())
	})

	Describe("Arguments()", func() {
		It("should return the aliased service ID", func() {
			typeDef := goldi.NewAliasType("foo")
			Expect(typeDef.Arguments()).To(Equal([]interface{}{"@foo"}))
		})
	})

	Describe("Generate()", func() {
		var (
			container *goldi.Container
			resolver  *goldi.ParameterResolver