Skip to main content
added 124 characters in body
Source Link
Slim
  • 109
  • 3

I'm trying to design a system that inject configuration of each component into each class.

project structure:

  |features
   --|component-a
        component-a.service.js
        component-a.config.json
   --|component-b
        component-b.service.js
        component-b.config.json
   --|component-c
        component-c.service.js
        component-c.config.json

I think about 2 approaches to inject the config:

  1. Create a class config which receives the name of the component and locate it, then initialize the attributes from the component-x.config.json file, and each component-xclass inherits from the class config.

  2. Use an injector that locate the configuration file for the dependent class when it will be needed for the client.

  3. Load the config file for each component and initialize the attributes inside the component constructor explicitly.

Which approach will be better to use with dependency injection pattern?

I'm trying to design a system that inject configuration of each component into each class.

project structure:

  |features
   --|component-a
        component-a.service.js
        component-a.config.json
   --|component-b
        component-b.service.js
        component-b.config.json
   --|component-c
        component-c.service.js
        component-c.config.json

I think about 2 approaches to inject the config:

  1. Create a class config which receives the name of the component and locate it, then initialize the attributes from the component-x.config.json file, and each component-xclass inherits from the class config.

  2. Use an injector that locate the configuration file for the dependent class when it will be needed for the client.

Which approach will be better to use with dependency injection pattern?

I'm trying to design a system that inject configuration of each component into each class.

project structure:

  |features
   --|component-a
        component-a.service.js
        component-a.config.json
   --|component-b
        component-b.service.js
        component-b.config.json
   --|component-c
        component-c.service.js
        component-c.config.json

I think about 2 approaches to inject the config:

  1. Create a class config which receives the name of the component and locate it, then initialize the attributes from the component-x.config.json file, and each component-xclass inherits from the class config.

  2. Use an injector that locate the configuration file for the dependent class when it will be needed for the client.

  3. Load the config file for each component and initialize the attributes inside the component constructor explicitly.

Which approach will be better to use with dependency injection pattern?

edited tags
Link
Slim
  • 109
  • 3
Source Link
Slim
  • 109
  • 3

Inject configuration files into the injector is it an antipattern?

I'm trying to design a system that inject configuration of each component into each class.

project structure:

  |features
   --|component-a
        component-a.service.js
        component-a.config.json
   --|component-b
        component-b.service.js
        component-b.config.json
   --|component-c
        component-c.service.js
        component-c.config.json

I think about 2 approaches to inject the config:

  1. Create a class config which receives the name of the component and locate it, then initialize the attributes from the component-x.config.json file, and each component-xclass inherits from the class config.

  2. Use an injector that locate the configuration file for the dependent class when it will be needed for the client.

Which approach will be better to use with dependency injection pattern?