drgomesp / cargo

:package: A Go dependency injection container that promotes low coupling and inversion of control
MIT License
34 stars 2 forks source link

Add support for registering service definitions through configuration files #4

Open drgomesp opened 8 years ago

drgomesp commented 8 years ago

One should be able to register service definitions through a configuration file, as the example below:

builder := NewBuilder()
definition := builder.Load("services.json")
krzysztof-gzocha commented 8 years ago

Imho Loader itself should not depend on file extension and should take some kind of map or generally a structure as a parameter. Then we can just add adapters for YAML, JSON, XML or whatever else. What do you think?

drgomesp commented 8 years ago

Good idea @krzysztof-gzocha. We could have something like:

type Configuration struct {
    Definitions []definition.Definition;
}

And the adapters would simply return an instance of Configuration. Is that what you were thinking?

krzysztof-gzocha commented 8 years ago

Exactly, but I'm not sure if path is really required inside config. I understand config as a service which knows all the definitions. I found it would be something abstract like Loader::load(path string) and it's implementation like JsonLoader::load() or YamlLoader::load().

Loader will return Configration for sure, but do we need path to be inside this returned object? I don't think so

drgomesp commented 8 years ago

@krzysztof-gzocha you're right. The Configuration should be unaware of how it gets created.