Should ServicedComponent constructor be "light"? - 02-08-2005 , 08:53 AM
I just spent a couple of days trying to make .NET component wrapped in a
ServicedComponent class to work. It used to work before and almost in a
sudden started throwing exceptions. After numerous trials and failures I
found out the following:
1. ServicedComponent class used Microsoft Enterprise Instrumentation
Framework assemblies for logging purposes. To simplify the code, I made a
wrapper class for EIF. Depending on how the instance of EIF wrapper was
instantiated, ServicedComponent instance instantiation either succeeded or
failed (with NullReferenceException).
2. General conclusion is that it's better to have static instances of
"heavy" components, otherwise it is instantiated on a call to default
constructor where it may fail.
However I am not very glad to come to such conclustion, because it does not
give me deterministic picture of what's going on. What are the primary
considerations for ServicedComponents dependent assemblies? Can they be
static? Instantiated from a constructor? On a first call? Can its robustness
be affected by making them pooled or JITA?
Thanks in advance
vagif @ online.no
Re: Should ServicedComponent constructor be "light"? - 02-10-2005 , 04:12 PM
Anything exposed as COM/COM+ can't be static, but it can call static
methods of other non-COM+ classes.
I don't think it's wise to have much processing in a COM+ constructor.
It can be nasty if an exception occurs in the constructor - will the
class instance still be created? How will the memory be freed? How will
the COM caller handle an exception rasied in the constructor?
I like to keep the COM+ constructors as light as possible. I put the
"heavy" processing in an "Init" method that I define inside the same
class. That way the constuction will succeed, and if there's a problem
in the Init method, the caller will still have an instance to the
object, so there's a well defined state at all times.
Re: Should ServicedComponent constructor be "light"? - 03-16-2005 , 08:07 PM
using object pooling features of COM+. It is normally helpful for
component that has long initialization time.
|Thread Tools||Search this Thread|