I would like to use inversify in react-redux application but only in the service layer and not via componenet
I have the service of a setting that need to call to API (Http service) I would like a kind of provider that will give me the option to call settingsService.get() in the actions.ts file
How do i initialize the objects of all my services
my actions.ts file: I guess to bring container here and use conainter.get... is a bad practice
export const increment = () => (dispatch: any) => {
dispatch({
type: INCREMENT
});
};
My settings Service
@injectable()
export class SettingsService implements Settings {
@inject(TYPES.Test) private testService!: Test;
get() {
// some api call
return this.testService.test();
}
}
My inversify.ts
const container = new Container();
function init() {
container
.bind<Settings>(TYPES.Settings)
.to(SettingsService)
.inSingletonScope();
container
.bind<Test>(TYPES.Test)
.to(TestService)
.inSingletonScope();
}
export { container, init };
My question :
1 - where do I initialize the services? is the definition in iversify.ts is ok? do I need to initialize the container in index.ts on the react app? now I call init() in index.ts
2 - how do I call to settingsService in the actions.ts ( action.ts is not class-based) is a redux action function
3- should easy to test
My stack
React, redux, typescript