Question

I'm a programmer who has never really used .dll files. Of cause, when I need 3rd party software, such as a graphics library, a library to help me create graphs etc. I do add the references/ddl files to my program and use them in my code.

Also, it seems like you can use .dll for a lot of different things, so I'd like the topic to concentrate on C#.

Right now I am working on a sanitizing library(?) (I think that is the correct term), which will be full of relevant methods that can sanitize variables in all sorts of different ways.

What I want to know is:

would there be any advantage to:

1) Write the methods to class library -> compile/build it -> add the library as a reference to the program - which would need to sanitize some variables ?

Or would it be exactly the same if I where to:

2) Create a new SanitizeClass in the program -> add all the sanitize methods -> call the methods from the SanitizeClass in the different classes in the program that needs to sanitize variables

In general, I also want to know when it is an advantage to use compiled class libraries. I'm thinking of speed, security, all of it.

Could anyone enlightenment me? :)

Was it helpful?

Solution

The key question is: does it make sense for more than one application to use the type? If so, it should be in a class library. If not, you may still want to put it in a class library just for the sake of separation (e.g. have one assembly per tier in an n-tier solution), but you could just put it in your application.

If your sanitization is general-purpose, then putting it in a class library would definitely be the right move.

I know of people who write almost no code in executable applications, and put almost everything in class libraries - so the application basically just wraps the class libraries. I don't tend to go quite that far myself...

OTHER TIPS

The first thought that comes to mind is re usability. Will this sanitize library be used ever outside of the application you're currently working on? If you are, then you don't want to have to reference an exe in the future, for that you want to build a DLL file (possibly even strong name it and GAC it) and then just reference that in the future.

Using libraries is useful when you want to share code between multiple programs.

If you think you will need your classes to sanitize data in more than one program, this is a good idea to put them in a library.

It is also a good idea to put layers of your application in different libraries (check n-tier architecture)

Additional assemblies will add a slight load time and memory overhead, but otherwise have no performance implications.

Security will only make a difference if you need different code access security (CAS) and will make use of CAS.

Generally there are three reasons:

  1. It makes things simpler. Putting everything in a single assembly is becoming unwieldy (this could include organisational/team issues).

  2. Reuse.

  3. You need separate assemblies. E.g. to have interfaces and implementation in different assemblies to allow AppDomains to be unloaded (e.g. for plugins).

I think the easiest way is to add SanitizeLibrary project as Library Class project to your solution and reference this project in your application. If you find it useful you may then extract library from current project and reference it as dll in your other projects.

if you would be reusing this code in different apps - ie: this would be some sort of shared library - then compile it as a dll

reg performance, please note any code which is executed against an external assemble would always be a bit slower than executing code within the same assembly

What is Class Lib?

We can create the class files in all .Net applications(C#.Net,Asp.net,Asp.net MVC)

In Java Its called as Package!...

In .Net we calling it as DLL(Dynamic Link Library)

If you are creating the classes in your application, you can use this classes only inside this application, You cannot use it in other applications.

If you create the class library You can use it in all the application.

When you have to Create and Use Class Lib?

When we writing the same code in different application,at the time we can create the class library and use it in all the application.

Example :

If you have export excel option in more than one application, you can write the export code in class library and you can use it in more than one application.

Real time Example:

Class is like dustbin in a Room and only room members can access it.

Class lib is like dustbin in a common place(College,Railway station) any one can access and use it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top