Web application design question

Web application design question

am 23.12.2007 12:27:49 von Frank Moyles

I am a developer with many years (approx 10years) development experience
using C++ for DESKTOP applications. I am writing a web application using
C#, and I wanted to ask a question about appropriate design.

My design is as follows:

I have an Application class, which delegates to various classes to
perform required functionality. The application class is responsible for
the following:


Authentication
Authorization
UserManagement
SystemAdmin

etc.


Because of the nature of the work that the Application class does, there
should not be more than one instance of it at any given time - since
both instances for example, may try to modify/save the same object to
database.

I was therefore thinking of implementing the Application class as a
Singleton. But then I rembered that a web application is different from
a desktop application, because you have several users requiring
authentication/authorisation etc at the same time - so maybe a Singleton
pattern would not be appropriate for web applications.

Even if I used a Singleton pattern - is the single instance restricted
to a particular users session - or does it apply server wide - i.e.
accross all sessions?

Any help and insight from experienced web application designers would be
much appreciated.

Re: Web application design question

am 23.12.2007 13:38:54 von Eliyahu Goldin

Why don't you just use existing asp.net classes found in the
System.Web.Security namespace?

If you want to wrap them into your code, you can make a set of classes that
we handle all these aspects based on the existing classes, like
securityManager, userManager etc, and all your pages will use these classes.

If you want to share these classes between several applications, make them
in a separate project as a class library and include it to different
applications.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"Frank Moyles" wrote in message
news:L6ednYGsCrxb2_PaRVnyiQA@bt.com...
>I am a developer with many years (approx 10years) development experience
>using C++ for DESKTOP applications. I am writing a web application using
>C#, and I wanted to ask a question about appropriate design.
>
> My design is as follows:
>
> I have an Application class, which delegates to various classes to perform
> required functionality. The application class is responsible for the
> following:
>
>
> Authentication
> Authorization
> UserManagement
> SystemAdmin
>
> etc.
>
>
> Because of the nature of the work that the Application class does, there
> should not be more than one instance of it at any given time - since both
> instances for example, may try to modify/save the same object to database.
>
> I was therefore thinking of implementing the Application class as a
> Singleton. But then I rembered that a web application is different from a
> desktop application, because you have several users requiring
> authentication/authorisation etc at the same time - so maybe a Singleton
> pattern would not be appropriate for web applications.
>
> Even if I used a Singleton pattern - is the single instance restricted to
> a particular users session - or does it apply server wide - i.e. accross
> all sessions?
>
> Any help and insight from experienced web application designers would be
> much appreciated.

Re: Web application design question

am 23.12.2007 15:01:35 von Registered User

On Sun, 23 Dec 2007 11:27:49 +0000, Frank Moyles
wrote:

>I am a developer with many years (approx 10years) development experience
>using C++ for DESKTOP applications. I am writing a web application using
>C#, and I wanted to ask a question about appropriate design.
>
>My design is as follows:
>
>I have an Application class, which delegates to various classes to
>perform required functionality. The application class is responsible for
>the following:
>
>
>Authentication
>Authorization
>UserManagement
>SystemAdmin
>
>etc.
>
Are these things your Application class does or things the web
application will have to do to support the Application class?
>
>Because of the nature of the work that the Application class does, there
>should not be more than one instance of it at any given time - since
>both instances for example, may try to modify/save the same object to
>database.
>
>I was therefore thinking of implementing the Application class as a
>Singleton. But then I rembered that a web application is different from
>a desktop application, because you have several users requiring
>authentication/authorisation etc at the same time - so maybe a Singleton
>pattern would not be appropriate for web applications.
>
How does this work with the desktop application? It would seem that if
user A is running one instance of the app on box A and user B is also
running an instance on box B, concurrency issues might exist. With a
web application is both instances will run on box C. The
functionality's container isn't radically different in this respect.

>Even if I used a Singleton pattern - is the single instance restricted
>to a particular users session - or does it apply server wide - i.e.
>accross all sessions?
>
>Any help and insight from experienced web application designers would be
>much appreciated.
Re-examine the desired core functionality and determine how/if it can
be used by multiple users at once. Any possible concurrency should be
handled within the application and not be limiting the application to
a single instance.

regards
A.G.

Re: Web application design question

am 24.12.2007 16:11:35 von vapor

I agree here. In addition, Singletons on the web are exceedingly difficult
to create especially across a server farm - throw in web gardens and it
becomes an expensive approach.

--
--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99

"Eliyahu Goldin" wrote in
message news:ePLmhDWRIHA.4752@TK2MSFTNGP05.phx.gbl...
> Why don't you just use existing asp.net classes found in the
> System.Web.Security namespace?
>
> If you want to wrap them into your code, you can make a set of classes
> that we handle all these aspects based on the existing classes, like
> securityManager, userManager etc, and all your pages will use these
> classes.
>
> If you want to share these classes between several applications, make them
> in a separate project as a class library and include it to different
> applications.
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]
> http://msmvps.com/blogs/egoldin
> http://usableasp.net
>
>
> "Frank Moyles" wrote in message
> news:L6ednYGsCrxb2_PaRVnyiQA@bt.com...
>>I am a developer with many years (approx 10years) development experience
>>using C++ for DESKTOP applications. I am writing a web application using
>>C#, and I wanted to ask a question about appropriate design.
>>
>> My design is as follows:
>>
>> I have an Application class, which delegates to various classes to
>> perform required functionality. The application class is responsible for
>> the following:
>>
>>
>> Authentication
>> Authorization
>> UserManagement
>> SystemAdmin
>>
>> etc.
>>
>>
>> Because of the nature of the work that the Application class does, there
>> should not be more than one instance of it at any given time - since both
>> instances for example, may try to modify/save the same object to
>> database.
>>
>> I was therefore thinking of implementing the Application class as a
>> Singleton. But then I rembered that a web application is different from a
>> desktop application, because you have several users requiring
>> authentication/authorisation etc at the same time - so maybe a Singleton
>> pattern would not be appropriate for web applications.
>>
>> Even if I used a Singleton pattern - is the single instance restricted to
>> a particular users session - or does it apply server wide - i.e. accross
>> all sessions?
>>
>> Any help and insight from experienced web application designers would be
>> much appreciated.
>
>

Re: Web application design question

am 25.12.2007 00:25:15 von Coskun

Hi Frank,

First of all, I would like to say that I agree with both of other MVP
friends. With custom profile, custom membership and custom authorization
providers that either you can write or find on the web, you can easily get
over these kind of problems.

If you insist about using your own stuff within your Application class with
a Singleton architecture, I would like to suggest you reading about "lock"
feature in C#.

All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com

"vapor" wrote in message
news:38ACFB4F-054E-4D62-AF05-58C35BBC7B61@microsoft.com...
>I agree here. In addition, Singletons on the web are exceedingly difficult
>to create especially across a server farm - throw in web gardens and it
>becomes an expensive approach.
>
> --
> --
> Regards,
> Alvin Bruney [MVP ASP.NET]
>
> [Shameless Author plug]
> The O.W.C. Black Book, 2nd Edition
> Exclusively on www.lulu.com/owc $19.99
>
> "Eliyahu Goldin" wrote in
> message news:ePLmhDWRIHA.4752@TK2MSFTNGP05.phx.gbl...
>> Why don't you just use existing asp.net classes found in the
>> System.Web.Security namespace?
>>
>> If you want to wrap them into your code, you can make a set of classes
>> that we handle all these aspects based on the existing classes, like
>> securityManager, userManager etc, and all your pages will use these
>> classes.
>>
>> If you want to share these classes between several applications, make
>> them in a separate project as a class library and include it to different
>> applications.
>>
>> --
>> Eliyahu Goldin,
>> Software Developer
>> Microsoft MVP [ASP.NET]
>> http://msmvps.com/blogs/egoldin
>> http://usableasp.net
>>
>>
>> "Frank Moyles" wrote in message
>> news:L6ednYGsCrxb2_PaRVnyiQA@bt.com...
>>>I am a developer with many years (approx 10years) development experience
>>>using C++ for DESKTOP applications. I am writing a web application using
>>>C#, and I wanted to ask a question about appropriate design.
>>>
>>> My design is as follows:
>>>
>>> I have an Application class, which delegates to various classes to
>>> perform required functionality. The application class is responsible for
>>> the following:
>>>
>>>
>>> Authentication
>>> Authorization
>>> UserManagement
>>> SystemAdmin
>>>
>>> etc.
>>>
>>>
>>> Because of the nature of the work that the Application class does, there
>>> should not be more than one instance of it at any given time - since
>>> both instances for example, may try to modify/save the same object to
>>> database.
>>>
>>> I was therefore thinking of implementing the Application class as a
>>> Singleton. But then I rembered that a web application is different from
>>> a desktop application, because you have several users requiring
>>> authentication/authorisation etc at the same time - so maybe a Singleton
>>> pattern would not be appropriate for web applications.
>>>
>>> Even if I used a Singleton pattern - is the single instance restricted
>>> to a particular users session - or does it apply server wide - i.e.
>>> accross all sessions?
>>>
>>> Any help and insight from experienced web application designers would be
>>> much appreciated.
>>
>>
>

Re: Web application design question

am 31.12.2007 03:20:32 von Alvin Bruney

> How does this work with the desktop application? It would seem that if
> user A is running one instance of the app on box A and user B is also
> running an instance on box B, concurrency issues might exist.

Not usually. With a desktop app, concurrency is only an issue if the clients
hit a common back end source.

--
--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99

"Registered User" wrote in message
news:l2nsm3l5r8c220p965qqa0gtp7iaqbne8i@4ax.com...
> On Sun, 23 Dec 2007 11:27:49 +0000, Frank Moyles
> wrote:
>
>>I am a developer with many years (approx 10years) development experience
>>using C++ for DESKTOP applications. I am writing a web application using
>>C#, and I wanted to ask a question about appropriate design.
>>
>>My design is as follows:
>>
>>I have an Application class, which delegates to various classes to
>>perform required functionality. The application class is responsible for
>>the following:
>>
>>
>>Authentication
>>Authorization
>>UserManagement
>>SystemAdmin
>>
>>etc.
>>
> Are these things your Application class does or things the web
> application will have to do to support the Application class?
>>
>>Because of the nature of the work that the Application class does, there
>>should not be more than one instance of it at any given time - since
>>both instances for example, may try to modify/save the same object to
>>database.
>>
>>I was therefore thinking of implementing the Application class as a
>>Singleton. But then I rembered that a web application is different from
>>a desktop application, because you have several users requiring
>>authentication/authorisation etc at the same time - so maybe a Singleton
>>pattern would not be appropriate for web applications.
>>
> How does this work with the desktop application? It would seem that if
> user A is running one instance of the app on box A and user B is also
> running an instance on box B, concurrency issues might exist. With a
> web application is both instances will run on box C. The
> functionality's container isn't radically different in this respect.
>
>>Even if I used a Singleton pattern - is the single instance restricted
>>to a particular users session - or does it apply server wide - i.e.
>>accross all sessions?
>>
>>Any help and insight from experienced web application designers would be
>>much appreciated.
> Re-examine the desired core functionality and determine how/if it can
> be used by multiple users at once. Any possible concurrency should be
> handled within the application and not be limiting the application to
> a single instance.
>
> regards
> A.G.