473,472 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2407
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brian Munroe | last post by:
I am just starting to learn the OO side of Python scripting, and I am a little confused on the following. Take the following example class: >>> class rectangle(object): z = 1 def...
2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
2
by: Gabriel Genellina | last post by:
Hi In the following code sample, I have: - a Worker class, which could have a lot of methods and attributes. In particular, it has a 'bar' attribute. This class can be modified as needed. - a...
20
by: syd | last post by:
In my project, I've got dozens of similar classes with hundreds of description variables in each. In my illustrative example below, I have a Library class that contains a list of Nation classes. ...
2
by: Steve James | last post by:
I am trying to mark an override method in a derived class as obsolete using the ObsoleteAttribute. The compiler, however is not picking up this attribute and is not generating a warning or an...
2
by: Vivek Ragunathan | last post by:
Hi Are the members in a static class in C# class synchronized for multiple thread access. If yes, are all static members in a C# class auto synchronized ? Regards Vivek Ragunathan
16
by: digitalorganics | last post by:
What's the difference between initializing class variables within the class definition directly versus initializing them within the class's __init__ method? Is there a reason, perhaps in certain...
0
by: buntyindia | last post by:
Hi, I have a very strange problem with my application. I have developed it using Struts. I have a TextBox With Some fixed value in it and on Submit iam passing it to another page. <html:form...
11
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.