2

I've got an application that needs to have multiple app domains to isolate potentially unsafe modules, and also provide a level of isolation for non-thread-safe code. Each module implements a common interface but will also include long-lived method calls (minutes).

In the distant past, when I did something similar, I used MarshalByRefObject but I've since read that WCF is now the preferred mechanism for communicating across the AppDomain boundary.

Since I want multiple app domains and each request may be long-lived, I see a couple of issues:

  • I explicitly need only a single thread to be executing "work" code at a given time (so WCF's default approach of instantiating a new host class for each request is an issue)
  • How to manage a list of appdomains/the appropriate endpoints to make the calls to (how to inform each AD what endpoint to use/how it should report the endpoint it chooses at random)

I'd initially planned to make the calls into the AppDomain asynchronous and have some form of queueing system internally that allowed me to monitor/retrieve results but in light of using WCF and the hassle of overriding enough to control instantiation of the service host object (to allow subsequent calls to be made to the same object), I'm starting to wonder if I should make all the calls blocking and allow the parent process to handle all the thread problems. of course, then I'd also need to make sure I've never got more than 1 call pending to a given app domain and perform queueing in the parent process.

Does anyone have any experience with a similar scenario/advice on a good architecture/link to a decent article?

Community
  • 1
  • 1
Basic
  • 26,321
  • 24
  • 115
  • 201
  • Honestly, with the tightly coupled control that you want of the AppDomains, I don't think WCF would be a good solution. The basic architecture design inherent in WCF is loosely coupled, service orient, and remote procedure call based. I believe WCF presents the wrong level of abstraction for your intended design. Just my 2 bits :) – Sixto Saez Aug 21 '12 at 12:46
  • @SixtoSaez Thanks - I don't disagree with you as the WCF model doesn't quite seem to fit, hence the number of questions I'm coming up with. I might just stick woth some `MarshalByRefObject` and see how it goes. Incidentally, if you'd like to post as an answer, I'll accept if I don't get any better alternatives. – Basic Aug 21 '12 at 12:48

1 Answers1

2

The WCF framework is great for writing service oriented applications using a message exchange pattern through a remote procedure call mechanism. The netNamedPipesBinding could be used to achieve "management" of separate AppDomains within the same physical memory space but that level of control is not what WCF was intended for.

Maybe something along the lines of this blog post from Jeffery Richter is better suited to what you are trying to do.

Sixto Saez
  • 12,610
  • 5
  • 43
  • 51
  • Thanks - I suspected as much. The article looks worth a read. – Basic Aug 21 '12 at 13:39
  • FWIW, The method described in that article is actually something [I've already tried](http://stackoverflow.com/questions/12053567/controlling-how-p-invoked-assemblies-are-loaded-into-different-app-domains) and it didn't work as the code I'm calling is in an unmanaged dll (Just in case anyone else stumbles across this and I finally get an answer on the other Q). Thanks again – Basic Aug 21 '12 at 14:33