Getting \"new transaction is not allowed because there are other threads running in the session\".
It has nothing to do with foreach loops or anything people usually
I don't think that this is only problem of not disposed contexts (context doesn't keep opened transaction - you would see it because of uncommitted changes). If you have this problem you most probably don't use the new context instance per request or you have some multi threaded / asynchronous processing on the shared context instance (= one connection). This exception says that multiple threads (probably multiple processed requests) are trying to use their own transaction on the same connection - that is not possible.
Corner case can be manual handling of connections provided to context but I guess you would mention it if you use it.
Edit:
Your factory doesn't provide per request context - it provides single context for all request!!! That static dictionary is shared among all request so the first creates instance and stores it under _DEFAULT
key and all other requests will use it.