473,985 Members | 39,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)Sess ion["User"]).UserId or
((UserInfo)Sess ion["User"]).UserName, etc.

Both ProjectWeb and Facade reference the Library project, as it contains all
the error logging code. (An implementation of Microsoft's ExceptionManage r
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.Cur rent.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.Cur rent.((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 1617
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 "BaseUserIn fo" 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
IExceptionPubli sher (from Microsoft's ExceptionManage r 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.goo glegroups.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 "BaseUserIn fo" 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
3581
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 error message "Fatal Python error: PyEval_RestoreThread: NULL tstate". Without the line "self.app = app" the error goes away. So I suppose the main window can't have a reference to the application class. Right? Using the global variable qApp...
6
2839
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 stumped again with this little love triangle. Here is some background: m_commands.h defines - struct command_callbacks, which contains - a struct conn * reference - struct command, which contains - a struct command_callback reference
1
1942
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. The question: When I use MyUserCtrl in a form, I must, from the form, make reference to both classes, i.e. even to "MyBaseClass". Otherwise, it will not work. How can I manage to skip referencing MyBaseClass? I tried to put both user controls in one...
6
5095
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) in search (no record) mode. When the search is executed, frmperson calls frmsearchresult (dim f as new frmsearchresult) which is a listing of persons. From frmsearchresults, frmperson is called (dim f as new frmperson) with the resulting...
2
1488
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 containing my specialized UserControls. In any of those views, I need to acess the _Default page (parent, several times removed). I would like a strongly typed mechanism, but at this point,
6
4085
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 forgive me beforehand if I ask anything really simple or ridiculous. I am going to simplify my query... the structure of my example is ---> page1.aspx ------> page1.aspx.vb --->control1.ascx for the sake of simplicity this is what I am trying...
2
1860
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. This gives me a compiler error. Can someone tell how do I access it. Thanks
3
3754
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 get a Circular Reference" error and cannot reference the project. Is there any way to find out the what Method or Project is causing the problem If I am on Project A tring to add Project B - I checked that A doesn't include B and B doesn't...
3
2946
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 better than the amount of errors I was originally getting on builds before I consilidated by UC's though :-) "Paul Hale" wrote:
0
10376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10192
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
11631
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10937
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8489
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7644
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6442
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.