2

If I have a class HelperClass that I'd like to use within a saga, I'd like to be able to inject an IHelperClass into the constructor.

The problem I'm running into is that sagas appear to be instantiated with an empty constructor; so while I can create a constructor that takes IHelperClass and use it in unit tests, the framework will always call the parameterless constructor.

I think I could use property injection, but since this helper class is "necessary," my understanding is that property injection (assuming it would work) is not a best practice.

So how can I do this without taking a hard dependency on the concrete HelperClass implementation?

4

1 回答 1

3

您不必担心帮助对象在 saga 上下文中的“必要性”,因为没有其他代码会直接实例化 saga。

简而言之,您可以在这里毫无顾虑地使用属性注入。

于 2016-02-04T08:49:42.107 回答