1

In my application I use Spring-Boot with cookies in authentication. On the front end, I use Angular2. In my bootstrap(...), I inject some classes, to make them as singletons - they work as services. Now, the issue that recently began causing problems, was that when user is on login webpage, there are multiple calls to the backend (fired from constructors of classes injected into the bootstrap function). This causes some issues later on, as the constructor wasn't fired in a proper way.

Now, I am wondering if there is a way to inject the class into a bootstrap, without initializing it? This sounds weird, but I guess this would solve the issue (btw, I am open to any other ideas and solutions to this problem).

uksz
  • 18,239
  • 30
  • 94
  • 161

1 Answers1

2
  • Move the initialization code from ServiceA out from the constructor to a method
  • Inject a service ServiceB that provides an observable that emits values on login-status-change and allows ServiceA to subscribe.
  • execute initialization code of ServiceA when subscription emits true (for login state "logged-in")
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • That is what I ended up doing. Thanks! – uksz Jun 30 '16 at 06:59
  • Gunter, could you take a look at this http://stackoverflow.com/questions/36794175/is-it-possible-to-reboot-app-without-page-refresh ? Ar – uksz Jun 30 '16 at 07:06