0

I have no experience using dll files, it's the first time that I am going to use dll files in my web application. Which is the correct way to think before start using/design my dll files?

Should I think some reusable functions of my app in general in order to put them in a dll file ? How should I think ? In which cases is a good idea to use dll files ?

Also, what about stored procedures with different number of arguments ? Is it good idea to use a dll file to execute my stored procedures?

Any advice would be appreciated.

Thank you.

michaalis
  • 131
  • 1
  • 4
  • 17
  • 1
    Let me put it like this: Why do YOU want to create DLLs? Stored Procedures, if you're talking about MS SQL, are stored in the database. – Alexander Jun 28 '13 at 09:30
  • I meant the code needed to be written in my aspx.cs file in order to execute the SP from the database. – michaalis Jun 28 '13 at 09:32
  • Have a look at this article http://stackoverflow.com/questions/1260952/how-to-execute-a-stored-procedure-from-c-sharp-program – Dev N00B Jun 28 '13 at 09:38

1 Answers1

1

This has turned into a bit of a ramble I am sorry but I am not sure of your level of knowledge so trying to keep this simple!

When designing your system you need to think about how you want to structure it. Just like in the real world it is nice to organise things in logical places rather than just pile them up in the middle of the room! In theory you could put everything inside the MAIN method of your application but that would be hard to read and maintain. So, instead we break things out into methods so that you can see what is happening more easily.

This then scales up into breaking methods out into classes. If you have lots of methods that all relate to a User then it would make sense to create a class called User and put all of the methods in that class. That way should you, or another developer, want to do anything that involves users you know that it is probably located in the User class.

Following on from there you may find that some classes make sense to be grouped together. For example you might have the classes User, Books, Location, Animal and think that these are all models of things so then you would create a Class Library containing them. This is compiled into a DLL. You might then think I want all of my Data Access code to be in another Class Library because it makes sense to group all of that together.

So, you can see it really comes down to how you think it is best to group things. The most common approach is to have your User Interface (whether that is MVC, Web Forms, Win Forms, WPF etc), then your Business Logic and then your Data Access as the three main layers. Of course, within each layer you may have multiple DLLs but it is just a way of organising things to make it easier for you to maintain and others to understand. It has never been a good idea to just dump everything in one big CS file!

Belogix
  • 8,129
  • 1
  • 27
  • 32
  • Thank you very much Belogix for your answer :) I got it, I think my main problem at the moment is that I do not have the whole Business Logic of the whole app. I have only some parts of the Interface and a general description of the logic. – michaalis Jun 28 '13 at 10:08
  • However, during the implementation stage if you find some omission/errors then you go back and maintain the particular dll files & classes ? – michaalis Jun 28 '13 at 10:10
  • 1
    Yes, the whole point of breaking out is to make maintenance easier! It is still best to architect the solution up-front. Then, as your start filling out the details you can start putting things in the right place. It is like a library in the physical world, you put the shelves up for Fiction not knowing which books will eventually go there but you know you will have some and that over time they will likely grow in number! – Belogix Jun 28 '13 at 10:10
  • Belogix what is your opinion about Stored Procedures ? Should I combined Stored Procedure code in aspx.cs within a dll file? However how can I handle the cases of Stored Procedures with different number of arguments ? – michaalis Jun 28 '13 at 12:25
  • Again, it is very much a case by case basis and no hard and fast rules. Say you go for a Data Access Layer (DAL) which I would recommend by the way, then you may have a class in there called `People`. In there you may have a method called `CreatePerson` with different signatures (one takes three params while another takes four). Then all you need to do is call the SP with the parameters passed in etc. Then you know if you ever need to change any SPs to do with people you go to DAL and that class. Now... There are lots of patterns you could / should look into like Repository / Unit Of work but – Belogix Jun 28 '13 at 12:30
  • it is obviously a vast subject. I would start with something simple and build on it. I am not sure if you are using Entity Framework or straight SQLConnection etc so all this advice is a bit vague but hopefully give you few pointers to get going. – Belogix Jun 28 '13 at 12:31
  • I am using straight SQL connection(connection string) / Stored Procedures and always I have in my mind MVC pattern. I was thinking about all of these different options/approaches but I needed someone to show me the correct direction. thank you for your answer :) – michaalis Jun 28 '13 at 12:48