471,337 Members | 1,080 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 1645
Well, in the second paragraph of your post you have basically laid out the
solution, which allows you to call

Common.MyLog4Net.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.MyLog4Net.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.GetLogger("")) ...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*******@yahoo.nospammin.com> wrote in message
news:F4**********************************@microsof t.com...
Well, in the second paragraph of your post you have basically laid out the
solution, which allows you to call

Common.MyLog4Net.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@usenet> 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.com>
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Aaron | last post: by
1 post views Thread by Peter Bär | last post: by
2 posts views Thread by Sidorf | last post: by
5 posts views Thread by David++ | last post: by
14 posts views Thread by Abhi | last post: by

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.