CAOs, Shared Interfaces, and Factory Pattern -
03-12-2007
, 01:38 PM
All, I'm trying to accomplish something very similar to the Server-
Side Factory implementation found in Rammer's "Advanced .NET
Remoting".
My requirements are as such:
- Use shared interfaces (to keep implementation off the client)
- Dynamically determine which remote object to call from factory
This is what I have:
/* Interface for Facade Factory */
public interface IRemotingFacadeManager
{
object GetFacade(Type type, ApplicationPrincipal
applicationPrincipal);
}
/* Interface for Remote Object */
public interface IRemoteFacade
{
string GetValue();
}
/* Implementation of Factory */
public class RemotingFacadeManager : MarshalByRefObject,
IRemotingFacadeManager
{
public object GetFacade(Type facadeType, ApplicationPrincipal
appPrincipal)
{
Type concreteType = GetConcreteType(facadeType);
object instanceObj =
Activator.CreateInstance(concreteType, new object[] {appPrincipal});
return instanceObj;
}
}
/* Implementation of Remote Object (BaseRemoteableFacade inherits
MBRO) */
public class RemoteFacade : BaseRemoteableFacade, IRemoteFacade
{
public string GetValue()
{
return "foo";
}
}
/* Client Implementation */
facadeManager =
Activator.GetObject(typeof(IRemotingFacadeManager) , <location>) as
IRemotingFacadeManager;
object facade = facadeManager.GetFacade(typeof(IRemoteObject),
applicationPrincipal);
My problem occurs that I get a class cast exception when casting the
facade object (transparent proxy) to an IRemoteFacade object.
Is the implementation I'm going after possible?
Thanks for any input!
Josh Collins |