[2005] Best practices and Modules question
I am new to ASP.Net 2.0. In my ASP.Net 1.1 project I had a Module that exposed public functions that returned Datasets, Datareaders etc from the database.
I cannot seem to find the Module Template in ASP.Net 2.0, does this not exist anymore?
Also, should I be using a Module in this form. The only problem with a class is that I would have to instantiate it on every page when I want to connect to the Database.
Re: [2005] Best practices and Modules question
You can use a Class in the same way.
Class.Yourmethod will work withouth instantiating it. As long as Yourmethod is Public.
Re: [2005] Best practices and Modules question
Quote:
Originally Posted by Besoup
You can use a Class in the same way.
Class.Yourmethod will work withouth instantiating it. As long as Yourmethod is Public.
Do you know if that is considered the best way? I want my database access code in a separate place than the form code behind.
Re: [2005] Best practices and Modules question
Quote:
Originally Posted by Besoup
You can use a Class in the same way.
Class.Yourmethod will work withouth instantiating it. As long as Yourmethod is Public.
You mean Static (as in C#) or Shared (as in VB).
Re: [2005] Best practices and Modules question
Quote:
Originally Posted by maikeru-sama
Do you know if that is considered the best way? I want my database access code in a separate place than the form code behind.
Pretty sure it's the best way... It's what I do in my VS 2005 web apps.
Yeah, I stand corrected on the declaration.. Harsh is right!
Re: [2005] Best practices and Modules question
Quote:
Originally Posted by maikeru-sama
Do you know if that is considered the best way? I want my database access code in a separate place than the form code behind.
Actually it largely depends on the type of application you are working on.
Search here and google for 3-tier application in .Net. There may exists different tiered and may be non-tiered ways for accomplishing the thing.
It is generally considered good to separate database layer from the rest of application.
You may also want to look into different Patterns and Practices at MSDN site.
Re: [2005] Best practices and Modules question
I don't know what the Module Template is so you probably should describe it a bit better.
Yes, it's alright to call a function on every page. Rule of thumb in ASP.NET is to open your connection as late as possible and close it as soon as possible, so that makes it perfectly acceptable to call a database open connection method on every page (or from a method that you call which in turn opens a connection).
Re: [2005] Best practices and Modules question
When I say Module Template, I mean adding a Module to the project.
After doing some research, I read that you cannot add a Module to a ASP.Net 2.0 project and that Microsoft is probably trying to get rid of them. This was nothing official from Microsoft, but someone's opinion, with regards to Modules going away.
I think you all are right. I just wanted to make sure that I am doing things the right way or one of the accepted ways when programming in ASP.Net 2.0.
When I get time, I am going to make a Class that has shared functions that is used to access my data.
I am interested in Encrypting the connection string inside of Web.Config, so I will probably move on to that in few.
Re: [2005] Best practices and Modules question