Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ioc container for modules #98

Merged
merged 9 commits into from
Mar 2, 2022
Merged

feat: add ioc container for modules #98

merged 9 commits into from
Mar 2, 2022

Conversation

qiansc
Copy link
Contributor

@qiansc qiansc commented Mar 2, 2022

No description provided.

@qiansc qiansc merged commit df15af0 into main Mar 2, 2022
@qiansc qiansc deleted the ioc branch March 2, 2022 10:53
@qiansc
Copy link
Contributor Author

qiansc commented Mar 3, 2022

  • add new modules:
    /packages/modules/your-module

  • use a module:
    <c-component src="@cosmic-module/your-module">

    • c-component will bootstrap the root element of the module.
    • The providers of @cosmic-module/your-module will be injected into conatiner in current context.
    • You can get container by inject('container'), although it is not recommended.
    • It loads /dist/index.css by default, you can turn it off by setting css=false.
  • export injectable service in module:

export {
   root: vueComponent,
   providers: [yourService],
   imports: ['@cosmic-module/dep-module'] // if your-module need other services which export by dep-module
}
  • use injectable service in vue
import {inject} from '@cosmic/core/parts';
import {MenuService} from '@cosmic-module/frame-menu-bar';
const menuService = inject('MenuService');
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant