I'm a newbie to Generics and the like.  And I'm sure that lots of folks have already been using the approach I'm about to talk about for some time now, but to me... this is freaking cool!

My project is the typical client/server situation.  The UI will be running on the client, but the Business & Data layers need to run on an application server.  I've selected .NET Remoting for my connection framework.

In my project skeleton, I laid had put a stub in for a Business.Proxy assembly who would be responsible for doing the .NET Remoting dirty work for me.  This would be the single point of entry from the client to the server.

On the server, I have a Business.Manager assembly that will house all of my manager classes, where the real work happens.  Then I have my Data.Model assembly containing my data entities (generated by LLBLGen).

My Presenter layer (MVP/Passive-View) needs to make calls into the server through the Business.Proxy, into the Business.Manager.  I expected to have a near 1-to-1 duplication of my Business.Manager classes in my Business.Proxy layer, with the Proxy layer exposing static methods that turned around and called the static methods on the Business.Manager classes, via Remoting.  I expected each method in the Proxy to end up being one or two lines of code to make the call.  Not too awful at first, but over time this would be a lot of seemingly duplicate code.

Well, Generics to the rescue.  The alternate approach I came up with this afternoon actually serves the Manager classes up directly to the Presenter, via the Proxy layer.  This allows the Presenter to work directly against the Manager classes instead of working against an abstracted copy in the Proxy classes.  And best of all, my Proxy layer consists of 1 class with 1 static method, and that's it!  Here's the Proxy:

namespace Business.Proxy
{
public class ManagerProxy<Manager>
where Manager : Business.Manager.Common.ManagerBase, new()
{
public static Manager GetManager()
{
RemotingConfiguration.Configure(
"Business.Proxy.dll.config", false);
return new Manager();
}
}
}

My calling code from the Presenter looks like this:

_Manager = ManagerProxy<MyManager>.GetManager();

And then my Presenter layer works directly against the manager, except any interactions taken against it happen on the server.  This made my day!


My next step is to see if I can get around having to list all of my managers out in the Remoting config file.