xmlking/ngx-starter-kit

WARNING in Circular dependency detected:

sunger opened this issue · 5 comments

WARNING in Circular dependency detected:
libs\auth\src\auth.service.ts -> libs\auth\src\auth.state.ts -> libs\auth\src\auth.service.ts

WARNING in Circular dependency detected:
libs\auth\src\auth.state.ts -> libs\auth\src\auth.service.ts -> libs\auth\src\auth.state.ts

@sunger thanks for informing. for now you can ignore this warning. I will see how I can avoid such circular dependency.

I may have to reference AuthState's selector as text. but it is not working at the moment.
@amcdnl is there a solution/workaround for this case?

    this.store.select(AuthState.authMode).subscribe(authMode => {
      console.log(`Auth Mode Changed: ${this.authMode} => ${authMode}`);
      this.authMode = authMode;
    });

may be like this:

     this.store.select('auth.authMode').subscribe(authMode => {
      console.log(`Auth Mode Changed: ${this.authMode} => ${authMode}`);
      this.authMode = authMode;
    });

You can try:
@Select(AuthState) authMode$: Observable<AuthMode>;

@eranshmil as long as you use/refer AuthState in AuthService you will get Circular dependency WARNING.
if you don't want to see warning, then you can try this.

  @Select('auth.authMode') authMode$: Observable<AuthMode>;

and 

    this.authMode$.subscribe(authMode => {
      console.log(`Auth Mode Changed: ${this.authMode} => ${authMode}`);
      this.authMode = authMode;
    });

with this approach, I see ngxs store fires change event twice. which I don't like :(

Console log:

Auth Mode Changed: undefined => undefined
Auth Mode Changed: undefined => ImplicitFLow

With static reference to AuthState ie. this.store.select(AuthState.authMode).subscribe(....) it only fire one time as I expected.

 Auth Mode Changed: undefined => ImplicitFLow

I'd guess that's because the auth service is being initialized before auth state.
I recommend you to move some of the logic from auth service into the state, for example:

    if (this.authMode === AuthMode.PasswordFlow) {
      // For Password Flow
      return this.ropcService.logOut();
    } else {
      // For ImplicitFlow
      this.oauthService.logOut();
    }

I don't see any reason for that to be in the service and not in an action.

fixed.