Register factory

This adds the feature to register a factory - that is a method that returns a new object.