Accept a lambda for context

Closes #467
Merge pull request #478 from haines/context_lambda

Accept a lambda for context in factory