implemented factory and optional dep selection.