我的工作,它包含的功能,約10個不同組件的應用程序西納特拉。我們希望能夠混合搭配這些組件到應用程序的不同實例,完全由config.yaml文件進行配置,看起來像:架構模塊化的,基於組件的應用西納特拉
components:
- route: '/chunky'
component_type: FoodLister
component_settings:
food_type: bacon
max_items: 400
- route: 'places/paris'
component_type: Mapper
component_settings:
latitude: 48.85387273165654
longitude: 2.340087890625
- route: 'places/losangeles'
component_type: Mapper
component_settings:
latitude: 34.043556504127466
longitude: -118.23486328125
正如你所看到的,組件可以被實例化更多每次都有自己的上下文設置。
每個組件包括至少一個路由的,從用於基本配置文件中的「路徑」屬性。
什麼是組織和實例化模塊代碼的最佳方式?
這很接近,但沒有考慮問題中提到的動態路由。即'/ chunky'不能被硬編碼。 –
好點。查看關於編輯。 – bioneuralnet
不錯!沒有想過在擴展代碼中迭代。最後一點:你的意思是'extend'而不是'use'?我似乎無法找到'use'的文檔。 –