dotnetnoob
dotnetnoob

Reputation: 11350

Should I use a class library project or a new web application?

I'm pretty new to the whole coding thing (hence the name). I've recently written my first website asp.net 4/Visual Studio etc.

I now want to write some code that can be shared amongst websites (my own only). At first I thought of a pluggable class library solution to store the code centrally, however, it seems a class library does not have certain things like config files to store my configuration,and I began to wonder if a class library is the right choice, or whether another web application would be better suited.

The solution will be code/configuration only with no pages.

So, a couple of questions.

Can a web app be incorporated into another web app?

Is a web app the right way or should I stick with a class library solution?

Is there a checklist I should follow before making such a decision?

Sorry if these questions appear rather basic, but as I said, I've little experience in this area.

Thanks in advance.

Upvotes: 0

Views: 681

Answers (2)

Jason P
Jason P

Reputation: 27022

It's absolutely a good idea to separate your webpages from the logic via class library projects.

"Can a web app be incorporated into another web app?" I believe only compiled code can be incorporated into other projects, and that wouldn't include aspx pages, so no.

"Is a web app the right way or should I stick with a class library solution?" - I prefer web app(s) with separate class libraries. Take the instance where you would want separate client-facing and admin sites, and maybe you have a call center version that is (for example) a native winforms application. I would have a solution with two webapp projects, a winforms project, and shared class libraries to support all three UI versions. We also have a couple standalone libraries (as in, not in the same solution as a webapp) like our logging or custom authentication solutions that we drop in to new web app solutions.

"Is there a checklist I should follow before making such a decision?" - I've created a VS template that has a web app project and a class library by default. I don't think there's any choice to be made, it's just what we do.

Upvotes: 1

Justin Helgerson
Justin Helgerson

Reputation: 25551

I always mix in class libraries with my web applications. I have many class libraries for each web application. Your class libraries will have access to the Web.config file for your web application, you just need to add the System.Configuration namespace.

I would break our your class libraries into logical pieces. As an example, I have a class library for database access, for third party API access, and another for active directory access. Break your libraries into logical pieces that can be easily reused among your other web applications.

Upvotes: 1

Related Questions