Let's talk about three projects. I have a Cinema project, a Cinema.Engine project, and a Cinema.Client1 project.
In the Cinema project, I have an interface ICinema and a factory class CinemaFactory.
In the Cinema.Engine project, I have a class that implements ICinema... we'll call it CinemaEngine : ICinema. This project is exposed as a WCF service referencing the Cinema project.
This allows my Cinema.Client1 project to only reference the Cinema project. The Cinema.Client1 can call the CinemaFactory and obtain a reference to the ICinema provided by the WCF service. All is well and good....... Now to get icky.
Let's add a fourth project called Cinema.Client2 which has references to both the Cinema and Cinema.Engine projects. Because I have a reference to Cinema.Engine, I want to be able to call my factory with a different set of parameters and have the factory instantiate the engine locally instead of calling the WCF service.
Important note: the Cinema project does not have any references to any other projects.
So, if I only have a reference to the Cinema project, then the factory should look like this:
public class CinemaFactory { public ICinema GetCinema (Uri RemoteCinema) {} } But if I have a reference to Cinema.Engine then the factory should look like this:
public class CinameFactory { public ICinema GetCinema (string CinemaParameters) {} } To put it another way: The client (residing in one project) needs to obtain an instance of the engine (residing in a second project). That instance will either be a proxy to a WCF service or it will be instantiated locally. This instance will be obtained from a factory (residing in a third project). The first project (containing the client) and the third project (containing the engine) both reference the second project (containing the factory).
If the client is obtaining the proxy, it shouldn't need a reference to the second project. If the client has a reference to the second project, only then should the factory provide the option of instantiating the engine locally.
How can I get the factory (in the third project) to instantiate the engine locally (from the second project) without having a reference to the second project (which causes a circular reference)?
Things I've looked into but that don't work:
- Partial classes don't work. Partial classes are syntactic sugar and cannot span projects.
- Same class, different namespace (for the factory): but how would I know which namespace to pull the class from?
newkeyword: only applies to members, not to entire classes.
Uriand one with astringas a parameter. Where is the problem?stringsignature, pass astringin the first example, and convert it to aUriwhen it arrives?Urihas a constructor overload that accepts a string. Your other alternative is to have two method signatures in yourInterface.Cinema.CinemaFactory, then I must also have a reference to theCinema.Engineproject. Not only does this cause a circular reference, but it means deploying theCinema.Engine.dllfile along with my client, which I'm trying to avoid.Cinema.Enginein the client? Can't you just alter the existingICinemainterface, or add a new interface in the same location?