Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
All my assemblies are dlls and no exes. There are two product P1.dll and P2.dll. A number of assemblies are having common functionalities and thus referred by both P1 and P2. Let me name them as Utility.dll, License.dll, Configuration.dll.

All the assemblies P1, P2, License and Configuration and any other dll refers Utility dll as it has methods to log, other helper functions etc.

The Utility dll has a static Log class which is static with methods like Exception(ex), Trace(String) etc.

The Utility dll also has a static App class with AppVersion, RootAssembly, AppTitle etc which is called during Log, or during any messaging from any dll etc. And the class has an Initialize method where these properties are set from P1 and P2.

Now the problem is once the Initialize is called by P1, and later used gets correct values, valid for P1. If at this time P2 calls Initialize on App and then if this properties are used by P1, the values are relevant to P2 and not P1, the reason being the App class is static.

But it is hard at this stage to change everywhere like in catch block I just call Log.Exception(ex) to pass App too by making it an instance class.

And since the Log.Exception is also a utility dll method, anything can be done to ensure 2 copies of App class exist or 2 memory space for the Utility dll itself?

Thanks in advance
Nishitha

What I have tried:

Read about AppDomain, but not clear how to apply for my scenario
Posted
Updated 17-Jan-18 5:17am
Comments
F-ES Sitecore 17-Jan-18 11:46am    
The problem is that you are abusing static classes, you have probably used static classes as they are easier to access, not because they are right for your solution. If these classes contain state they should not be static, you need to refactor your code so that these classes are not static.
Alex Schunk 19-Jan-18 16:03pm    
Sorry my friend... Your application is broken by design.

1 solution

If you do this in order to change your code you will ruin your codebase.

Tell your PM you need to refactor.

And then refactor.

Or you will bay for it on the back end a hundredfold.

You are following anti-patterns, and trying correct anti-patterns with more anti-patterns.

This way be dragons.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900