Skip to content

How to use dependencies in your code

Because the generation of dependencies is done automatically by TWIZZAR the dependencies cannot be used in the code without using the ItemContext. The ItemContext is a class that is generated by TWIZZAR and contains all dependencies of the requested instance. To get a ItemContext the Build(out var context) method of a Custom Item Builder must be used.

c#
var potion = new BluePotionBuilder()
    .Build(out var context);
var potion = new BluePotionBuilder()
    .Build(out var context);

To get a dependency, the context's Get method of the context can be used.

c#
var potionColor = context.Get(p => p.Color);
Assert.That(potionColor, Is.EqualTo(potion.Color));
var potionColor = context.Get(p => p.Color);
Assert.That(potionColor, Is.EqualTo(potion.Color));