Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 14th, 2008, 11:26 PM
Registered User
 
Join Date: Jul 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to lok_tan
Default Share a non-remotable singleton object

Here's the scenario:

A & B are remote objects hosted under IIS
Everytime A & B get invoked, they need to get some value/data from another object (call it C).

For example, C is an ConfigurationReader that will read an external config file, and put all the data inside a dictionary.

When any method of A or B get invoked, it needs to get specific value/data from C.


The problem is (please correct if I'm wrong):

I'm hosted these objects (A & B) under IIS, so I don't have any chance to do any initialization for C, since reading the external config file should be done ONLY ONCE.

This lead to the pattern that C should be a singleton object. So whenever it being called by A or B (via static method C.GetInstance()), it will always return the same instance of C that already been initialized once.


The question:

Is there anyway to realize this scenario?


Any advise or guidance will be greatly appreciated. Thanks.

Regards,

Lok
 
Old March 15th, 2008, 11:30 AM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've found this page to be most helpful http://www.yoda.arachsys.com/csharp/singleton.html
 
Old March 15th, 2008, 07:59 PM
Registered User
 
Join Date: Jul 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to lok_tan
Default

Thanks for the link.

Under ordinary scheme, hosting remote-object inside windows apps/windows service architecture, the singleton patterns are working perfectly.

The problem here, I'm hosting the remote-object inside IIS, so I don't have any control to manage how the apps will start-up, how the remote-object been initialized, etc.

Actually, I can put the initialization routine inside Global.asax.cs, but the one that I don't know, how to "connect" between my remote-object and all the instance that I already declare/initialize inside Global.asax.cs, since it's not an ASP.NET apps.

Anyway thanks for your help.

regards,

Lok
 
Old March 17th, 2008, 01:14 AM
Registered User
 
Join Date: Jul 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to lok_tan
Default

Already found the solution by using Global.asax, and initialize all the singleton object inside Application_Start :D

Topic closed.
 
Old March 17th, 2008, 04:00 AM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If the initialization routine isn't very long just put the code inside singleton-object's constructor (and use that full lazy pattern). That way it is initialized the first time object is called and only once.

But glad that you got it working :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
provider class singleton not thread safe trystanc BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 October 25th, 2007 12:32 AM
how can share my databse lalit_84m SQL Server 2000 1 May 31st, 2007 01:05 AM
How to share along several projects Demeter Visual Studio 2005 2 July 14th, 2006 07:49 AM
Singleton Usage in Clustering and EJB argupta BOOK: Expert One-on-One J2EE Design and Development 0 December 17th, 2003 12:44 AM
how to share a folder mqnguyen Classic ASP Basics 2 August 6th, 2003 01:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.