Hi everyone,
I'm creating a serviced component in C#, and was thinking about calling
the Construct() method to cache a string in a local variable, for later use.
In VB6 I had it burned into me that caching values in a COM+ component
wasn't maybe the best idea, given how COM+ and JIT worked. I was told that
with JIT you're not guaranteed to use the same component between method
calls, so trying to hold state in a variable is asking for trouble.
Was that line of reasoning correct, and if so, does it hold in .Net as
well, and should I avoid caching a string in the Construct method because of
it? Thanks,
-Jim
Klaus H. Probst - 18 Nov 2004 22:03 GMT
There is no difference between VB6 and .NET because the technology (COM+) is
exactly the same. A ServicedComponent is just a fancier way to implement
IObjectControl.
As for how it works, you're right that you're never guaranteed the same
instance, not should you ever expect that. However, you're mixing two
concepts. IObjectConstruct is just a feature of COM+ where your
implementation gets an arbitrary string every time an instance of it is
created. I don't see how this is related to state or caching. You should
never cache the string value for the simple reason that you'll get it every
time you activate. You can of course save the string value to a scoped
instance variable in your class and use it later during the call sequence
that activated your object instance to begin with.

Signature
Klaus H. Probst, MVP
http://www.vbbox.com/
> Hi everyone,
>
[quoted text clipped - 10 lines]
>
> -Jim