473,378 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Accessing Class / Circular Reference

Consider these three projects:

- ProjectWeb (my web application)
- Facade (my class library, does data access, etc.)
- Library (a library of classes I reuse in applications)

ProjectWeb references Facade, and on login adds an instance of a
Facade.UserInfo class (a User class) into the user's Session. The session is
called Session["User"], and I can reference the UserInfo properties by
doing: ((UserInfo)Session["User"]).UserId or
((UserInfo)Session["User"]).UserName, etc.

Both ProjectWeb and Facade reference the Library project, as it contains all
the error logging code. (An implementation of Microsoft's ExceptionManager
application block)

In the Library class, there's an error logging class that needs the current
user's UserId in order to write a record into the error log table. I'd like
to grab this from the UserInfo instance that's in Session. I have access to
HttpContext.Current.Session["User"], but I have to cast the object to
UserInfo in order to access it's properties.

Ideally, I would access the UserId property like this:
HttpContext.Current.((UserInfo)Session["User"]).UserId

However, I can't do that because Library would have to reference Facade
(circular reference) in order for me to have access to the UserInfo class in
my code.

Any suggestions on how to do this, without having to create new Session
variables for the UserId?

Thanks!

Nov 19 '05 #1
2 1585
If your Library needs to reference an object in Facade, is it really
reusable in other applications? By storing the ID (specific to this
app), you're further making Library application specific.

I think those "violations" are what are causing your headache.

The simple fix I can see is to pass the UserID into the "write an
error" routine in library. Then it doesn't have to know anything about
the Facade.UserInfo class.

The more complex fix is to make a "BaseUserInfo" class in Library.
Define it MustInherit (not sure if this is the same keyword in
C#...that's how we'd do it in VB), and include in it anything that
Library needs to know about a user to do its job. Then you can extend
that class in Facade, and add any application specific things to it,
but still pass a user to Library.

As usual, someone else probably has a better idea, but there's my
$0.02. :)

Nov 19 '05 #2
Thanks Phillip,
You're right about the "violations". Having it access something in the
UserInfo class would kill this reuse.

The error insert function is part of a class that inherits from
IExceptionPublisher (from Microsoft's ExceptionManager application block),
so I might try to modify that to take in a UserId.

If I can't change that method signature, I will opt to go with the
BaseUserInfo solution.

Thanks again Phillip

George

"Phillip Ian" <ph****@comcast.net> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
If your Library needs to reference an object in Facade, is it really
reusable in other applications? By storing the ID (specific to this
app), you're further making Library application specific.

I think those "violations" are what are causing your headache.

The simple fix I can see is to pass the UserID into the "write an
error" routine in library. Then it doesn't have to know anything about
the Facade.UserInfo class.

The more complex fix is to make a "BaseUserInfo" class in Library.
Define it MustInherit (not sure if this is the same keyword in
C#...that's how we'd do it in VB), and include in it anything that
Library needs to know about a user to do its job. Then you can extend
that class in Facade, and add any application specific things to it,
but still pass a user to Library.

As usual, someone else probably has a better idea, but there's my
$0.02. :)

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sibylle Koczian | last post by:
Still trying to learn PyQt from a book about several Python GUI toolkits, I seem to learn first what doesn't work. The following small script seems to work, but after closing the window I get the...
6
by: T Koster | last post by:
After a few years of programming C, I had come to believe that I finally knew how to correctly organise my structure definitions in header files for mutually dependent structures, but I find myself...
1
by: M Shafaat | last post by:
Hi! I have made a user control called, say "MyUserCtrl", which is inherited from another user defined class called, say "MyBaseClass". Each one of these two are developed in its own project. ...
6
by: Stephen Robertson | last post by:
We are currently in a dead end with a circular reference issue using vb.net, and are hoping someone might help us resolve it. Idea... We have frmmain calling frmperson (dim f as new frmperson)...
2
by: RKT | last post by:
(Web Developer Express 2005, CSharp, C#) I've searched high and low... If have the typical _Default page. In it is a MultiView that contains another MultiView - in both of those are Views...
6
by: evandelagrammaticas | last post by:
Hi all. I have spent the better part of a day scouring the newsgroups and I am sure that I must have come across the solution a number of times - but I am still a real newbie at asp.net so please...
2
by: Asfar | last post by:
Hi, I have a form Form1 in my application. I now create a generic class Test1. In this class I declare a variable of type Form1. I also include the header file for the form in this class. ...
3
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I Have a solution with about 50 projects and each project have References to 1 to n of the projects in the solution. I try go to a project and try to add a reference to another project and I...
3
by: =?Utf-8?B?UGF1bCBIYWxl?= | last post by:
Moving all User Controls to a single directory has solved my problem - Thanks Eliyahu. That said, I still got one Circular ref error yesterday, rebuilt again and the build was fine? Far far...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.