Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Component Services / March 2005

Tip: Looking for answers? Try searching our database.

Should ServicedComponent constructor be "light"?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vagif Abilov - 08 Feb 2005 13:53 GMT
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 Abilov

Oslo Norway
vagif @ online.no
Eric - 10 Feb 2005 21:12 GMT
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.

Eric
Chee Pin Cheam - 17 Mar 2005 02:07 GMT
> Anything exposed as COM/COM+ can't be static, but it can call static
> methods of other non-COM+ classes.
[quoted text clipped - 11 lines]
>
> Eric

Eric is right. Nothing in COM+ can be static due to context sensitivity.
 If you have long initialization for your component, you can consider
using object pooling features of COM+. It is normally helpful for
component that has long initialization time.

Chee Pin

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.