Running An Agatha Service Layer In-Process (Without WCF)
I’ve mentioned previously that Agatha does not require you to use WCF. You can build your Request/Response Service Layer and host it through WCF, or you can just as well ‘host’ or run it in-process. Why would you want to do that? Well, suppose you’re working on a web application where you don’t really need (or want) to have your business logic running behind a WCF service. Using a Request/Response Service Layer in this scenario still offers you quite a few architectural benefits: your service layer would basically be some kind of dynamic facade to your business layer where you can still centralize the way you deal with transactions, exceptions, logging and any other cross cutting concerns you want to handle in one place. As an added bonus, you could very easily move your service layer and its business logic to a separate machine/service and host it through WCF without any major modifications to your code. It would actually be trivially easy as long as your service layer doesn’t share state in any way with your upper layers (presentation layer or application layer if you will).
Let’s see how easily you can use your Request/Response Service Layer in-process with Agatha. Do you remember the full-blown Hello World, Agatha Style example? Let’s try to use that service layer and use it in-process without WCF. First of all, I added a new project to my sample solution. It references both the Sample.Common and the Sample.ServiceLayer assemblies. Sample.Common contains my Request/Response types, and Sample.ServiceLayer contains the Request Handlers that the service layer consists of. To configure both the client-side components (mainly the request dispatchers) as well as the server-side components (mainly the request processor and your request handlers), we just need to do this:
And that’s it. No WCF configuration necessary. No required XML at all. The ServiceLayerAndClientConfiguration class will take care of everything and you can use your Request/Response Service Layer both synchronously and asynchronously in your code. The service layer will behave exactly the same as it would when running on another machine or in a different process through WCF. And you’ll still get to benefit from all of the advantages that Agatha can offer you.
Note: I made some changes to the codebase after the 1.0 beta 2 release to make this so easy (and also to get the async stuff working properly when running in-process) so you will need to use the current trunk version (as of revision 38) or wait for the next release.
Written by Davy Brion, published on 12/8/2009 7:00:05 AM