Skip to content

Commit 82f73ed

Browse files
Marcarriandanielwiehl
authored andcommitted
fix(solace-message-client): do not eagerly construct SolaceMessageClient
Previously, the SolaceMessageClient was constructed during application startup. This caused problems if OAuth authentication was enabled and the access token provider depended on services that were only available after the application was started. Instead, the SolaceMessageClient is now constructed on first use. closes #53
1 parent 9905b3e commit 82f73ed

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

projects/solace-message-client/src/lib/solace-message-client.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import {provideLogger} from './logger';
7575
@NgModule({})
7676
export class SolaceMessageClientModule {
7777

78-
constructor(@Inject(FORROOT_GUARD) _guard: any, _solaceMessageClient: SolaceMessageClient /** eager construction */) { // eslint-disable-line @typescript-eslint/no-empty-function
78+
constructor(@Inject(FORROOT_GUARD) _guard: any) { // eslint-disable-line @typescript-eslint/no-empty-function
7979
}
8080

8181
/**

projects/solace-message-client/src/lib/solace-message-client.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ describe('SolaceMessageClient', () => {
6666
await expectAsync(solaceMessageClient.session).toBeResolved();
6767
});
6868

69+
it('should not eagerly construct `SolaceMessageClient`', async () => {
70+
TestBed.overrideProvider(SolaceMessageClient, {
71+
useFactory: () => {
72+
throw Error();
73+
},
74+
});
75+
expect(() => TestBed.inject(SolaceMessageClientModule)).not.toThrowError();
76+
});
77+
6978
it('should allow to disconnect and re-connect from the Solace message broker', async () => {
7079
const solaceMessageClient = TestBed.inject(SolaceMessageClient);
7180
await simulateLifecycleEvent(SessionEventCode.UP_NOTICE);

0 commit comments

Comments
 (0)