Classes derived from ServicedComponent do not support constructors with arguments?

Z

zlf

I am asked to complete a COM+ component, there is a class A derived from
ServicedComponent.
However, when executing [new A("TEST");], exception is thrown.

Messaged:
Unhandled Exception:
System.EnterpriseServices.ServicedComponentException:
Classes derived from ServicedComponent do not support constructors
with arguments


class A:ServicedComponent
{
public A(){};
public A(string name){};
}

new A("TEST");

Please tell me how to make class derived from ServicedComponent support
constructors with arguments.
Thank you.

zlf
 
N

Nicholas Paldino [.NET/C# MVP]

zlf,

You can not construct a serviced component derived class and have a
constructor. The reason for this is that serviced components are meant to
follow the COM+ architecture. This requires interface implementations, with
default, parameterless constructors.

If you want to store the value, expose a method that takes the parameter
and store it.

BTW, the class definition that you have is pretty much worthless. You
need to attribute it correctly in order to get any kind of use out of it.
Additionally, you should really be exposing an interface and implementing
that.

Hope this helps.
 
Z

zlf

Thank you.
I tell show this to designes and force them to change the design:)

Nicholas Paldino said:
zlf,

You can not construct a serviced component derived class and have a
constructor. The reason for this is that serviced components are meant to
follow the COM+ architecture. This requires interface implementations,
with default, parameterless constructors.

If you want to store the value, expose a method that takes the
parameter and store it.

BTW, the class definition that you have is pretty much worthless. You
need to attribute it correctly in order to get any kind of use out of it.
Additionally, you should really be exposing an interface and implementing
that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

zlf said:
I am asked to complete a COM+ component, there is a class A derived from
ServicedComponent.
However, when executing [new A("TEST");], exception is thrown.

Messaged:
Unhandled Exception:
System.EnterpriseServices.ServicedComponentException:
Classes derived from ServicedComponent do not support constructors
with arguments


class A:ServicedComponent
{
public A(){};
public A(string name){};
}

new A("TEST");

Please tell me how to make class derived from ServicedComponent support
constructors with arguments.
Thank you.

zlf
 
N

Nicholas Paldino [.NET/C# MVP]

You have to be careful when you design this stuff as well. For example,
if you are going to use transactions, or just in time activation, or object
pooling, you have to be aware that you are not going to necessarily have the
same object every time (object pooling), or, that the state of the object
will be maintained between calls (JIT activation, transactions).

Because of that, in these situations, you can't do this:

MyObject obj = new MyObject();
obj.Initialize("a");
obj.MyMethod("some parameter");

Because in between the call to Initialize and MyMethod, you might have a
different object, or you can't be expected to have retained the state from
one call to the next.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

zlf said:
Thank you.
I tell show this to designes and force them to change the design:)

Nicholas Paldino said:
zlf,

You can not construct a serviced component derived class and have a
constructor. The reason for this is that serviced components are meant
to follow the COM+ architecture. This requires interface
implementations, with default, parameterless constructors.

If you want to store the value, expose a method that takes the
parameter and store it.

BTW, the class definition that you have is pretty much worthless. You
need to attribute it correctly in order to get any kind of use out of it.
Additionally, you should really be exposing an interface and implementing
that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

zlf said:
I am asked to complete a COM+ component, there is a class A derived from
ServicedComponent.
However, when executing [new A("TEST");], exception is thrown.

Messaged:
Unhandled Exception:
System.EnterpriseServices.ServicedComponentException:
Classes derived from ServicedComponent do not support
constructors with arguments


class A:ServicedComponent
{
public A(){};
public A(string name){};
}

new A("TEST");

Please tell me how to make class derived from ServicedComponent support
constructors with arguments.
Thank you.

zlf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top