Reputation: 11360
I udnerstand that if I have 2 different DLLs, and in each of them I instantiate the same object as a static (e.g., private static MyObject objRandom = new MyObject();), 2 instances of it will be created.
What if I were to pass the static object from DllA to DllB via dependency injection, will I only have 1 instance of it created in the stack?
Upvotes: 0
Views: 295
Reputation: 8372
The object is not static, the reference is. You can have as many references to the same instance as you want. The thing that is static in your example is the reference in your class so different instances of the same class that contains static MyObject objRandom...
will have the same instance.
If the same object is referenced by other class, in a static or non-static fashion, is ok. Even if that class is in another DLL.
Hope it clarifies how it works.
Upvotes: 0
Reputation: 43748
It depends some on your code, but most likely it would be 1 instance. Statics are instantiated per AppDomain, not per DLL. Your DLLs are all loaded into the same app domain.
Upvotes: 1