473,691 Members | 3,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pass reference cross classes via method call?

I am trying to find a way to not have to reference an object in all my
projects, since it is initialized & instantiated in my Common class.

I have a 4 tier project (presentation, rules, dal, common) where my common
project initializes and configures things such as log4net (and several
others). However, I can't simply call MyLog4Net.Warn( ""), no matter if I
create the common class as a singleton with a public accessor returning
MyLog4Net, or if I set MyLog4Net as a public static member variable in
Common (even if Common is a struct, instead of a class).

With all these ways, I still have to reference log4net, AND Common, in all
my other tiers. I want to just call Common, which only that references
log4net, and not have all my tiers referencing both of these objects. How
is this possible? Is there some Marshalling attribute, or some type of
Reflection call that can be made/returned from the Common class, so as to
not have to have all my other projects reference an abundance of .dll files?

TIA
-John
Nov 29 '05 #1
3 1752
Well, in the second paragraph of your post you have basically laid out the
solution, which allows you to call

Common.MyLog4Ne t.Warn("")

why is this such a big deal?
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"John E." wrote:
I am trying to find a way to not have to reference an object in all my
projects, since it is initialized & instantiated in my Common class.

I have a 4 tier project (presentation, rules, dal, common) where my common
project initializes and configures things such as log4net (and several
others). However, I can't simply call MyLog4Net.Warn( ""), no matter if I
create the common class as a singleton with a public accessor returning
MyLog4Net, or if I set MyLog4Net as a public static member variable in
Common (even if Common is a struct, instead of a class).

With all these ways, I still have to reference log4net, AND Common, in all
my other tiers. I want to just call Common, which only that references
log4net, and not have all my tiers referencing both of these objects. How
is this possible? Is there some Marshalling attribute, or some type of
Reflection call that can be made/returned from the Common class, so as to
not have to have all my other projects reference an abundance of .dll files?

TIA
-John

Nov 29 '05 #2
Thanks for the reply.

It won't let me access any methods within MyLog4Net (i.e. the Warn("")
part), unless each of my projects not only references my Common project, but
also the log4net project.

e.g.

Project: A
|--> References: Common
Project: Common
|--> References: log4net

Project A cannot call Common.MyLog4Ne t.Warn()

Unless the Common project wraps each method in log4net, I cannot access any
log4net method. Even if Common has public static log4net variable (e.g.
public static log4net.ILog MyLog4Net = log4net.GetLogg er("")) ...or via an
accessor, or if Common is a singleton, or if Common is a struct.

So, currently the only way to access the log4net methods is to do the
following:

Project: A
|--> References: Common, log4net
Project: Common
|--> References: log4net

It seems a lot worse when you have an n-teir project all with references to
Common, log4net, Config, Util, etc.

Does that help clarify? Any ideas on how to resolve this overkill of
referencing?

Thanks,
-John
"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com > wrote in message
news:F4******** *************** ***********@mic rosoft.com...
Well, in the second paragraph of your post you have basically laid out the
solution, which allows you to call

Common.MyLog4Ne t.Warn("")

why is this such a big deal?
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"John E." wrote:
I am trying to find a way to not have to reference an object in all my
projects, since it is initialized & instantiated in my Common class.

I have a 4 tier project (presentation, rules, dal, common) where my common project initializes and configures things such as log4net (and several
others). However, I can't simply call MyLog4Net.Warn( ""), no matter if I create the common class as a singleton with a public accessor returning
MyLog4Net, or if I set MyLog4Net as a public static member variable in
Common (even if Common is a struct, instead of a class).

With all these ways, I still have to reference log4net, AND Common, in all my other tiers. I want to just call Common, which only that references
log4net, and not have all my tiers referencing both of these objects. How is this possible? Is there some Marshalling attribute, or some type of
Reflection call that can be made/returned from the Common class, so as to not have to have all my other projects reference an abundance of .dll files?
TIA
-John

Dec 1 '05 #3
John E. <PleaseReply@us enet> wrote:
Thanks for the reply.

It won't let me access any methods within MyLog4Net (i.e. the Warn("")
part), unless each of my projects not only references my Common project, but
also the log4net project.


Does this happen even if your MyLog4Net class doesn't have *any* public
(or protected) members which depend on Log4Net? If the calling code
doesn't (and can't) know of the dependency on Log4Net, I would expect
it to be okay.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 1 '05 #4

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

Similar topics

4
11584
by: Gerhard Pretorius | last post by:
ON Win 2003 IIS6, Since yesterday, (12 Aug 2003) for some strange reason, (after installing WindowsServer2003-KB823980-x86-ENU.exe) I cannot pass the Request object to to VB COM DLL. I have a funciton inVB DLL Function BuildSqlWhereFromHTML(ByRef AspReq As ASPTypeLibrary.Request, _ ByRef AspSes As ASPTypeLibrary.Session) As String
2
2152
by: Aaron | last post by:
I have a data sructure setup and I populate it in a loop like so: y=0 while X: DS.name = "ASDF" DS.ID = 1234 list = DS; y = y + 1
1
2719
by: Peter Bär | last post by:
A Question to the C#/.Net Gods of this forum: are there performance penalties when i compile (C#, FW1.1, ASP.NET, Studio2003) a central baseclass in a different assembly than all the derived classes? f.i. ive got a class dbobject i project "Basesupport", compiles to Basesupport.dll. From dbobject i derive about 100 classes, thy all are located in Project
2
1490
by: Sidorf | last post by:
Hi It's a little hard for me to explain my problem, but i'll try. I have an application in which i have a ManagerClass, many ClientClass-es ans some ControlClass. The ManagerClass creates one or more instances of ClientClass. ClientClass creates some controls from ControlClass. In the ControlClass i have derived some common control classes and added some functionalities.
2
2265
by: Peter Bär | last post by:
A Question to the C#/.Net Gods of this forum: are there performance penalties when i compile (C#, FW1.1, ASP.NET, Studio2003) a central baseclass in a different assembly than all the derived classes? f.i. ive got a class dbobject i project "Basesupport", compiles to Basesupport.dll. From dbobject i derive about 100 classes, thy all are located in Project
10
2503
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++) { items = "item" + (i + 1);
5
7819
by: David++ | last post by:
Hi folks, I would be interested to hear peoples views on whether or not 'pass by reference' is allowed when using a Web Service method. The thing that troubles me about pass-by-reference into a WebService is that essentially we are passing an address of an object which resides on the 'local machine' i.e. a local machine object address. Surely when the WebService method is called and run 'on the server', the reference type will be...
14
20392
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is passed also. I understand that this way of passing the array is by value and if the prototype is declared as foo(int *), it is by reference in which case the value if modified in the function will get reflected in the main function as well. I dont...
12
11090
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
0
8531
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,...
0
9077
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8793
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...
0
7623
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5811
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
4322
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...
0
4550
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2965
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 we have to send another system
3
1952
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.