Handle namespaces correctly for DGFE

#include statements must occur outside namespaces.
Template instantiations require switching forth and back between namespaces.