Angular2 StrategyPattern injecting services

Viewed 59

Given the following Strategy-Pattern:

enter image description here

And the fact that the strategies itself are Services, injecting other Services (doing HTTP Calls, etc)

How can one set/unset the strategies in the StrategyHolder? I implemented the following scenario to just get some code running, but there must be a better solution then injecting the services in the strategy Holder like:

constructor(
private strategyOne: Strategy1,
private strategyTwo: Strategy2) {...}

and then switching through the strategies like:

setStrategy(...)

I was wondering, if one uses the StrategyHolder in his Angular Component, he should just be able to pass a strategy to the holder, as of course strategies are not known by the holder, as any one can implement the strategy interface and provide its own strategy.

So the question is: What is the Angular-way of implementing the possibility to set an unknown strategy from within the Angular Component, that does just inject the StrategyHolder?

Thank you in advance!

0 Answers
Related