When I was working on my most recent social networking project, we introduced an interest construct that we began referring to as the “Viewing Context”. Before explaining what this was used for, I’ll further explain the construct. The following diagram illustrates the scenario:
Figure 1.1
The construct simply embodies the notion of having a particular Business Object in the viewing context of the current page. For example, given some Url ‘ViewUser.aspx?UserId=1′ we would consider a UserViewContext to be available to the page. The following diagram illustrates the identification of viewing contexts:
Figure 1.2
This was particularly useful as we began to leverage the power of Role-based security. We identified roles that were associated with each ViewingContext, illustrated by the following diagram:
Figure 1.3
Consider the following sample population:
| ViewingContext | Role |
|---|---|
| UserId | Friend |
| UserId | Blocked |
| UserId | FriendshipPending |
Given some UserViewingContext, we know that ‘Friend’, ‘Blocked’, and ‘FriendshipPending’ are applicable roles. We then devised a ‘BaseRoleManagerModule’ to inject roles based on the current viewing context. This opened up a variety of opportunities for us for UI development.
Consider the following business rule:
R101
Some User x may view some User y’s profile if at least one of the following is true:
- y has set profile privacy settings to ‘Public’ and x is not in the role ‘Blocked’
- y is equal to x
- x is in the role ‘Friend’
This could now be enforced with the following method:
Figure 1.4
There’s certainly more advantages to this than simplifying business rule enforcement but I thought I would focus on that for the introduction of the construct.
What are your thoughts? Is this an idea that can be reused or is it one of those one-time implementations?
If you like this blog please take a second and subscribe to my rss feed
Tags: architecture, ASP.Net, c#, Code, design patterns, new constructs
Comments: 2 comments
All the fields that are marked with REQ must be filled
Ryan Abreu
July 19th, 2008 at 3:57 am
very well done. this is a very interesting implementation of your project’s view-related business rules, and it seems to work great for the project you’re using it in.
Jason
July 19th, 2008 at 8:08 am
I must admit I was a bit confused at first but after talking to Josh it makes sense. I think another way to look at the ViewingContext is to call it your RelevantPrincipal.
Leave a reply