Skip to content

Dependency injection from shell to parent #793

Open
@erikwski

Description

@erikwski

With what library do you have an issue?

module-federation

Reproduction of the bug/regression with instructions

How to reproduce

Pull this repo: https://github.com/erikwski/POC-MFE-ABSTRACTION.git

  • Install the dependency at least on the folder cdo, clm-shared, shell
  • Run the npm run build inside the clm-shared
  • Use npm link for link clm-shared with cdo and shell
  • Start locally the cdo and the shell
  • Open the shell at localhost:4200 and click the button navigate to CDO
  • Injection Error

Explanation:

I need to implement an abstraction class in two different shell, the abstraction will be in a shared folder and the implementation must stay in the shell folder.
How can i declare to my remote that it will receive the abstract from the shell? Now the error that it's throwing is:

ERROR NullInjectorError: R3InjectorError(Environment Injector)[DataService2 -> DataService2]: 
  NullInjectorError: No provider for DataService2!
    at NullInjector.get (_angular_core.55F2ZY8DZy-dev.js:943:21)
    at R3Injector.get (_angular_core.55F2ZY8DZy-dev.js:1289:27)
    at R3Injector.get (_angular_core.55F2ZY8DZy-dev.js:1289:27)
    at ChainedInjector.get (_angular_core.55F2ZY8DZy-dev.js:2839:32)
    at lookupTokenUsingModuleInjector (_angular_core.55F2ZY8DZy-dev.js:3012:31)
    at getOrCreateInjectable (_angular_core.55F2ZY8DZy-dev.js:3038:10)
    at ɵɵdirectiveInject (_angular_core.55F2ZY8DZy-dev.js:10527:17)
    at ɵɵinject (_angular_core.55F2ZY8DZy-dev.js:701:59)
    at inject (_angular_core.55F2ZY8DZy-dev.js:710:10)
    at <instance_members_initializer> (app.component.ts:14:27)

I want to reproduce something that i already make using monorepo like this: https://github.com/erikwski/clm-monorepo/tree/master/libs/shared/notification/feature-emit/src/lib

Expected behavior

I need to understandand how to declare dependency injection of the remote to take some services from the parent.

Versions of Native/Module Federation, Angular, Node, Browser, and operating system

"@angular-architects/native-federation": "^19.0.16",
"@angular/core": "^19.0.0",
Node: v20.18.0
Browser: Chrome 134.0.6998.89
OS: Windows 11

Other information

Probably i'm just missing something or it's not possible but i need an answer and maybe open a discussion if it's possible

I would be willing to submit a PR to fix this issue

  • Yes
  • No

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions