4

So I have the following project structure:

apps
├── car
└── [...]
libs
├── app-car
├── [...]
└── shared
    ├── config
    └── [...]

For every app I want to provide a different config, that can be used in the grouped libs.

export interface DefaultAppConfig {
  language: string;
}
export interface CarAppConfig extends DefaultAppConfig  {
  dealerShipName: string;
}

This is how I provide the config for every app.

But how can I typecast the config (placed in shared/config) that the CarAppConfig is used only for the group app-car and DefaultAppConfig for shared?

dewey
  • 809
  • 2
  • 16
  • 47
  • 1
    Could you clarify your question a little more? I think you're asking how to have strongly-typed configuration per app, but using a config service (to load configuration) which is in `shared`. Is that right? – Matt Tester Nov 15 '21 at 23:05
  • @MattTester I haven't thought of the placement yet, but placing it in `shared/config` would be a good option. I also edited the question and added the placement of the service. `libs/shared` is a group of libs. Libs that are used across all apps are placed here. Yes I want a strongly-typed configuration per app – dewey Nov 16 '21 at 07:19

1 Answers1

3

From what I can understand, IMHO, you should keep DefaultAppConfig in shared/config and CarAppConfig in app-car.

Reason: As the name suggest, shared is shared by all libs. So, why should other app have access to an object which is out of its scope.

You can extend DefaultAppConfig in all apps and use it in its app-car.module or something.

Side note: You can also explore the concept of Tags to have more control over what can be imported into a lib and what should not.

Please let me know if I get it correctly.

Shashank Vivek
  • 16,888
  • 8
  • 62
  • 104