re-motion mixins basics -- instantiation with parameters

re-motion in general uses parameter lists for passing parameters for constructors to the object factory. The mechanism is explained in the PhoneBook tutorial for NewObject<T> (section NewObject<T> with parameters).

For every class for which you want to have instantiation with parameters, you must create a constructor. Let's say you want a DessertTopping with flavors:

public enum Flavor

What you need is a constructor for DessertTopping that does the right thing:

public DessertTopping (Flavor flavor)
  // we assume that 'DessertTopping' now has a
  // 'Flavor Flavor' property
  Flavor = flavor;

You are basically set. Instantiation does ***NOT*** work like this:

ObjectFactory.Create<DessertTopping> (Flavor.Licorice)

It works like this:

ObjectFactory.Create<DessertTopping> (ParamList.Create (Flavor.Licorice));

ParamList.Create () returns a parameter list object and is a generic, strongly typed method (although it doesn't look like it). The object factory's Create<DessertTopping> finds the matching constructor by reflection (if you have declared that constructor) and calls it automatically.

If the empty parameter list (ParamList.Empty) is passed, then the default constructor is used.