Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 722 Bytes

use-without-ioc.md

File metadata and controls

23 lines (17 loc) · 722 Bytes

Use without IoC

Example how to use BBT.StrategyPattern without IoC.

public void GenericStrategyWorksInMemory()
{
    var calc1 = new CalculationInput() { Number1 = 5, Number2 = 3 };
    var op1 = new Operator() { Operation = OperatorEnum.Addition };
    var op2 = new Operator() { Operation = OperatorEnum.Subtraktion };

    var factory = new MemoryOperatorStrategyLocator();
    var strategyProvider = new GenericStrategyProvider<IOperatorStrategy, Operator>(factory);

    IOperatorStrategy strategy;

    strategy = strategyProvider.GetStrategy(op1);
    strategy.DoCalculate(calc1).Should().Be(8);

    strategy = strategyProvider.GetStrategy(op2);
    strategy.DoCalculate(calc1).Should().Be(2);
}