I have a rather unusual problem and need some ideas.
I maintain two codebases that are 99% identical. A new project has come along that under some runtime condition needs to use code base A and in other conditions use precompiled code base B.
I have abstra开发者_StackOverflow社区cted the functionality into an interface for the project and plan to have two implementation assemblies that reference the different code bases. I plan on using a service locator pattern to instantiate the object. So it looks a little like this.
Assembly A (Website) Assembly B Libraries
-------------------------------|--------------------|-------------
Project -> Service Locator -> Implementation A -> Code Base A
-> Implementation B -> Code Base B
My concerns lie around in loading the same named assemblies of code base a and b and having runtime conflicts.
What is the best approach for this scenario and why?
It sounds to me that if you give each assembly a different name it would effectively solve the problem. Even though the code base in each assembly would be nearly identical, assemblies are identified by name (and other characteristics), so naming them differently would ensure that they don't collide. The types (classes etc.) inside each assembly use the assembly name to build their fully qualified names, so you shouldn't have any conflicts there.
However, the interface behind which you hide the assembly types must be defined in a third library (which might be your consuming library).
精彩评论