?
Solved

Best method for Global Shared Functions for Web Applications in C#

Posted on 2011-05-06
9
Medium Priority
?
384 Views
Last Modified: 2012-05-11
All knowing Gurus,

As a newly minted newbie from the vb.net world I am trying to create a central reposity for my most often used C# 2.0 functions that will be used by all of my single application code modules.  From what I've been able to gleen from the postings static variables and functions are the way to go however nothing is mentioned about where such variables and functions are supposed to go or in what format or file type.  

In your experience please enlighten in a best practices kind of way with recommended folder locations for C# 2.0.

regards,

Ted
0
Comment
Question by:tcalbaz
  • 5
  • 3
9 Comments
 
LVL 9

Expert Comment

by:radcaesar
ID: 35707997
Create a webservice with your functions

Deploy it on a central server

Consume that weservice's methods whereever you want in other applications.
0
 
LVL 1

Author Comment

by:tcalbaz
ID: 35708152
radcaesar,

Each of my applications will have its own common functions.  

C# is unforgiving. What do i need to do to achieve this?  

I am sure it is more then creating an aspx or aspx.cs file, popping in some common functions and calling it a day?

This is why I need specifics.

regards,

T.

0
 
LVL 1

Author Comment

by:tcalbaz
ID: 35708260
radcaesar,

Using Web services is a brilliant idea however I feel that would not be an appropriate solution in this case.  

All I need or want is a place to store my common functions and variables and the where, what and how to do this in C# 2.0

regards,

T.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 13

Accepted Solution

by:
iHadi earned 2000 total points
ID: 35708267
I suggest you wrap them up in a class library project (dll). This approach has a lot of advantages like:

- Clean and Blackbox design: The functions are not and should not be related to any specific application. Simply it will be a blackbox that has specific input and specific output.

- Better for team development: You can have a developer working on the class library and another on the app without one interfering with other code.

- Easier to Update and deploy: If you add features or fix bugs in the library, you do not need to recompile and deploy the whole solution, you just need to deploy the dll.

- Easier to integrate into new apps: If you have a new application that needs to use the library's functions, all you need to do is reference the library. No need to copy, paste and add cs files

- Central repository for your functions: If you discover a bug in your functions, all you need to do is fix it in the library's project, compile it and deploy it to all your applications, That is much easier than fixing the code of the cs files in each and every app that is using the functions and recompiling them all and then deploying them.

- Protect your code: This is my favorite feature. When I have my developers working on any project as a team, they have access to all the code but the core library functions, which I make sure they get it compiled and protected. This will help me protecting myself from source code theft (ofcourse not 100%) because the cannot benefit from what he stole without the library's code. It also can back me up in who owns the code arguments.
0
 
LVL 13

Expert Comment

by:iHadi
ID: 35708282
Add to the above the privilege of your application to work offline
0
 
LVL 1

Author Comment

by:tcalbaz
ID: 35708738
iHadi,

OK - you got me all excited.  A library is exactly what I want!  How do I create it in c#? (I am a newbie)

This will be my first one so give it to me step by step.  An example would be nice.

regards,

Ted

0
 
LVL 13

Expert Comment

by:iHadi
ID: 35709081
Creating a dll library is very simple, it's just like creating any other VS projects. When creating a new project, select the Class Library template.

Class Library projects cannot run alone. They produce only a dll that should be run n another project type context link windows forms,web applications, WPF, ...

So to test your code, add another project to your solution that can run standalone like windows forms or web applications.

To be able to use the classes from the library in your test project, you must add a reference to the class library. This can be done through the the add reference command in the right click menu on in the solution explorer. You can either browse for the dll in the bin folder of the class library project, or you can reference the whole library project which I prefer.

The class library is in theory a collection of classes in a separate project, so you should not have any issues moving your classes to the new project, and using them in your other projects is just the same as using any .net class or any other local class.
0
 
LVL 1

Author Closing Comment

by:tcalbaz
ID: 35832424
iHadi,
Thank you very much for your solution. Sorry for the delay. (I was locked out of my workstation for two weeks due to contract renewal delays) I look very much forward to implementation of your approach.
0
 
LVL 1

Author Comment

by:tcalbaz
ID: 35841108
To All,

This link provides a step by step solutioni for creation of DLL's in C#

http://www.homeandlearn.co.uk/csharp/csharp_s16p1.html
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question