I have a class that will have to use a strategy development template. At runtime, I have to switch different algorithms to see effects on application performance.
Currently, the class in question takes four parameters in the constructor, each of which is an algorithm.
How to use Ninject (or a generic approach) can I use IOC, but use a strategy template?
The current limitation is that my kernel (container) is aware of each interface of the algorithm, but this can only be associated with one specific class. The only way I can see at the moment is to go through all eight algorithms in the construction, but use different interfaces, but this seems completely incomplete. I would not have done this if I had not used the IOC container, so there should be something like that.
Code example:
class MyModule : NinjectModule { public override void Load() { Bind<Person>().ToSelf(); Bind<IAlgorithm>().To<TestAlgorithm>(); Bind<IAlgorithm>().To<ProductionAlgorithm>(); } }
A person must use both algorithms so that I can switch at runtime. But only TestAlgorithm is bound, since it is the first in the container.
c # design-patterns strategy-pattern ioc-container ninject
Finglas
source share