Add custom attributes to ServicedComponent

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

is it possible to use custom context-attributes with serviced components?

[AttributeUsage(AttributeTargets.Class)]
public class Logging : ContextAttribute
{
public Logging() {...}
public override void GetPropertiesForNewContext(IConstructionCallMessage
ctorMsg) {...}
}

[Logging]
public class LogMe : ServicedComponent
{

}

Thanks in advance,

Stefan
 
Hi Stefan,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know if it is possible to
use customer context-attributes with classes that inherit from
ServicedComponent. If there is any misunderstanding, please feel free to
let me know.

As far as I know, this is possible. I have checked the code you have
provided. Generally, it's correct. However, none of the ContextAttribute
constructors accept 0 arguments. Here I made a little change to your code.
HTH.

[AttributeUsage(AttributeTargets.Class)]
public class Logging : ContextAttribute
{
public Logging(string name) : base(name)
{}
public override void GetPropertiesForNewContext(IConstructionCallMessage
ctorMsg) {}
}

[Logging("newname")]
public class LogMe : ServicedComponent
{

}

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Kevin,

thanks for your prompt answer. Unfortunately there was a little
misunderstanding.

The attribute-instance itself is created, but GetPropertiesForNewContext
isn't called (which happens when i use the same attribute, but derive my
LogMe-Class from ContextBoundObject).

Precisely my question should have been: Is it possible to use
ContextAttributes with ServicedComponents to intercept function calls?
(ContextAttribute, IContextProperty, IMessageSink)

Thanks,

Stefan
 
Hi Stefan,

Do you mean that you need ContextAttributes to affect LogMe class in the
GetPropertiesForNewContext call? I think we cannot do that. Because
attributes are used to provide information for classes passively. It cannot
do anything actively on the applied classes. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Stefan,

According to the article, presently, .NET contexts and interception are
undocumented aspects of .NET. So it's not supported.

However, if this can apply to all classes to .NET framework, it can be used
on ServicedComponent. But IMO, I don't recommend to do so, because if it
fails, there is few resources for us to find for help.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Lucas Ottoni said:
Hi guys,

Did anyone know what we have to do to use IMessageSink with ServicedComponent?

Thanks for any help

Use IMessageSink is the same as use the custom attributes as described in this full thread
 
Back
Top