469,926 Members | 1,656 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

Getting a class instance from within the applied attribute

I've started looking at Aspect Oriented Programming but I've stumbled at a
problem I can't solve.

I want to add an Aspect that would notify a UnitOfWork that the current
DomainObject has changed so that it can be marked as Dirty.

I've created an Attribute, MessageSink and ContextProperty and everything is
working.

So when a property is accessed a function in the MessageSink class is
executed and the only thing the DomainObject has to do is add [SaveChanges]
to the class declaration.

But how can I pass the current DomainObject to my UnitOfWork? The funciton
in the MessageSink doesn't know about the DomainObject where the attributed
is used and I don't know how to find out on which DomainObject the property
is accessed.

Thnx for your help!

Wouter de Kort

Nov 17 '05 #1
2 2270
Wouter,

First, it should be noted that using context bound objects is not aspect
oriented programming. It offers method interception (which aspect oriented
programming has), but that's about it. AOP offers much more than just that.

In order to know ^which^ object is being intercepted, you will have to
implement IContributeEnvoySink or IContributeObjectSink. They both take
references to the MarshalByRefObject which is the ContextBoundObject that is
specific to that object. This allows you to set up an instance of your sink
which is tied to just that object (not all objects of the type).

The IContributeObjectSink will contribute a sink which is called in the
server context, while the IContributeEnvoySink will intercept the call in
the client context.

Additionally, you should ask if you truly want to use context bound
objects in this situation. You are going to take a performance hit (much
more than say, placing a method in each property which will set a flag
internally indicating that a change has been made) because of what is needed
to take the values on the stack and construct them into a message.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wouter de Kort" <Wouter de Ko**@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.com...
I've started looking at Aspect Oriented Programming but I've stumbled at a
problem I can't solve.

I want to add an Aspect that would notify a UnitOfWork that the current
DomainObject has changed so that it can be marked as Dirty.

I've created an Attribute, MessageSink and ContextProperty and everything
is
working.

So when a property is accessed a function in the MessageSink class is
executed and the only thing the DomainObject has to do is add
[SaveChanges]
to the class declaration.

But how can I pass the current DomainObject to my UnitOfWork? The funciton
in the MessageSink doesn't know about the DomainObject where the
attributed
is used and I don't know how to find out on which DomainObject the
property
is accessed.

Thnx for your help!

Wouter de Kort

Nov 17 '05 #2
Thnx for your advice :)

I know AOP is much more that intercepting method calls but this was my first
atempt at using it.

I'm trying to implement a system which would subscribe a class instance
automatically with a UnitOfWork and which would notify the UnitOfWork if the
class changed so updates can be written to the database.

It's just a test of the whole AOP idea.. if it doesn't work out I will just
go with the 'call method on each property'.

Do you have any other suggestions as how to implement the functionally I
want? Is there another, faster, way to intercept the method calls?

Thnx for your help,

Wouter de Kort

"Nicholas Paldino [.NET/C# MVP]" wrote:
Wouter,

First, it should be noted that using context bound objects is not aspect
oriented programming. It offers method interception (which aspect oriented
programming has), but that's about it. AOP offers much more than just that.

In order to know ^which^ object is being intercepted, you will have to
implement IContributeEnvoySink or IContributeObjectSink. They both take
references to the MarshalByRefObject which is the ContextBoundObject that is
specific to that object. This allows you to set up an instance of your sink
which is tied to just that object (not all objects of the type).

The IContributeObjectSink will contribute a sink which is called in the
server context, while the IContributeEnvoySink will intercept the call in
the client context.

Additionally, you should ask if you truly want to use context bound
objects in this situation. You are going to take a performance hit (much
more than say, placing a method in each property which will set a flag
internally indicating that a change has been made) because of what is needed
to take the values on the stack and construct them into a message.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wouter de Kort" <Wouter de Ko**@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.com...
I've started looking at Aspect Oriented Programming but I've stumbled at a
problem I can't solve.

I want to add an Aspect that would notify a UnitOfWork that the current
DomainObject has changed so that it can be marked as Dirty.

I've created an Attribute, MessageSink and ContextProperty and everything
is
working.

So when a property is accessed a function in the MessageSink class is
executed and the only thing the DomainObject has to do is add
[SaveChanges]
to the class declaration.

But how can I pass the current DomainObject to my UnitOfWork? The funciton
in the MessageSink doesn't know about the DomainObject where the
attributed
is used and I don't know how to find out on which DomainObject the
property
is accessed.

Thnx for your help!

Wouter de Kort


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Brian Munroe | last post: by
2 posts views Thread by Fernando Rodriguez | last post: by
2 posts views Thread by Gabriel Genellina | last post: by
20 posts views Thread by syd | last post: by
2 posts views Thread by Steve James | last post: by
2 posts views Thread by Vivek Ragunathan | last post: by
reply views Thread by buntyindia | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.