• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

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

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
tcalbaz
Asked:
tcalbaz
  • 5
  • 3
1 Solution
 
radcaesarCommented:
Create a webservice with your functions

Deploy it on a central server

Consume that weservice's methods whereever you want in other applications.
0
 
tcalbazAuthor Commented:
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
 
tcalbazAuthor Commented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
iHadiCommented:
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
 
iHadiCommented:
Add to the above the privilege of your application to work offline
0
 
tcalbazAuthor Commented:
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
 
iHadiCommented:
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
 
tcalbazAuthor Commented:
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
 
tcalbazAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now