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

Error when router object should be used via injection #57

Open
gruenich opened this issue Oct 20, 2023 · 3 comments
Open

Error when router object should be used via injection #57

gruenich opened this issue Oct 20, 2023 · 3 comments

Comments

@gruenich
Copy link

We are in the process of updating FTK in our application from version 0.3.2 to version 0.4.3.
We followed the migration guidelines at https://github.com/mercedes-benz/mo360-ftk/blob/master/docs/guides/migration.md.
Therefore, we schematically adapted our original init() function as follows:

function init(container: IDiContainer): void {
     container.bind<RouteConfigType>(serviceIds.routes).toConstantValue([
         {
             action: () => {
                 return () => <View1/>
             },
             name: "View1",
             path: '/view1',
         },
         {
             action: () => {
                 return () => <View2/>
             },
             name: "View2",
             path: '/view2',
         },
           ...

     ]);
}
    
export default() => {
     return (
         <>
             <App name="ApplicationName" init={init} config={config}>
                 <MuiThemeProvider theme={DUITheme}>
                     <CssBaseline>
                         <TranslationProvider translations={TranslationsI18n}>
                             <RouterProvider />
                         </TranslationProvider>
                     </CssBaseline>
                 </MuiThemeProvider>
             </app>
         </>
     );
};

Unfortunately, at runtime when we want to use the router object via injection

class View1 extends React.Component<IViewProps, IViewState> {

     @inject()
     public router!: RouterService;
     
      ...
      this.router.getRoute().name;
      ...
     
}

we get following error message:

Error: Can't inject router as no binding for type function Object() {
[native code]
} was found. Did you register it in the DiContainer?
get inject.js:34

@prode81 Can you tell us what we are doing wrong here or how we can avoid this mistake?

@DerLeviathan
Copy link

Hi,
we updated FTK from @daimler/ftk-core v0.4.3 to @mercedes-benz/ftk-core v0.4.5 but we are experiencing the exact same issue (same error message when using the injected router).
@prode81 Can you please check why this is still the case and what we are doing wrong?
Thank you & best regards

@prode81
Copy link
Collaborator

prode81 commented Dec 6, 2023

Hey @DerLeviathan, we will investigate further. Sorry, this did not the trick for you.

@DerLeviathan
Copy link

Hi @prode81, do you already have some update on this issue. Thank you & best regards.

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

No branches or pull requests

3 participants