I am looking at creating a ServiceManager area (set of classes with a facade interface) where other areas can sign up to and offer "services" via, and pass on requests. I plan on running this class in its own thread, and I want to keep critical regions at a minimum and handled purely within this area.
When an area sign up they get their own inbox and outbox of commands, which is a List of ServiceRequests.
Now my dilemma is, if I do not share the link to the outbox (the service providers area) I will need to locate the box via a search for a match (critical region across all signing up, and due to this all submitting requests as well, defeating the purpose of a local outbox).
Alternative I give a link outside of the ServiceManager area, then a new external area is coded it is possible to skip the critical region and directly update the list, bypassing this.
My solution is to within the code of the ServiceManager area to create a "key" object where direct access never leave the area (any object including a complete empty will work).
When an area is signed up, they are getting a class in return, where a link to the above object along with a link to the where the ServiceManager object of the signed up area. (which contains direct inbox/outbox link along with other information).
This "token" object also contains following code
public ServiceObject GetServiceObject(Key key)
{
If (key == this.key)
{
return serviceObject;
}
return null
{
this way even if the command is public its contents can only be accessed within the ServiceManager area as its the only area with direct access to the Key object. This bypass above two concerns of having a shared critical region across all service users, and the risk of those service users accessing their lists directly.
So it solves the problem but to me this looks real ugly, is there a smarter approach, and if how?