1

I'm working on a C# assignment. I have to design my C# application as 3 layer, where the layers have to be implemented in their own packages. To solve this, i just added folders to my project in Visual Studio. Is this the right approach?

Then i have to implement the business logic as a .dll (library). What i have done is to create a new Class Library project in my Solution. What i have right now is:

Screenshot of my Solution Explorer

I'm not sure about how to do this. Is it correctly done? If so, i want to know what to do now. As far as i know, i have to build the Class Library project to get the .dll file, which i can add as reference to the other project. But if i write my business logic in the Class Library project, then what am i supposed to write in my BusinessLogic package in the main project?

If my approach is wrong, please tell me how to solve this.

Fth
  • 105
  • 2
  • 19
  • Each DLL will be a separate Class Library project in Visual Studio. Using folders just organizes the code files. So you need three class libraries - one for each "layer" – D Stanley Oct 28 '16 at 18:58
  • It seems that the idea of the assignment is to teach you separation-of-concerns, the 3 layers are meant to be loosely coupled and each of the layers is oriented towards one aspect of the application. For example in MVVM you have a control layer (where you put your UI controls), a view-model layer (objects the UI bind to) and a model layer (business logic, services etc). First before you even start I would suggest spending some time on the design phase and decide what to put in each layer. If you want you can create separate projects for each of the layers. – brakeroo Oct 28 '16 at 19:14
  • Seems like your BusinessLogic package should be a class library that provides an interface for other "layers" to use its functionality. Can you give more information about the project, I want to come up with an example but the question is a little too abstract. – brakeroo Oct 28 '16 at 19:15
  • For example it could be a management system for a library with different kind of customers who can borrow, buy and sell books. In the end i need to store a kind of receipt and show (print) it. – Fth Oct 29 '16 at 09:59
  • Addition: It's only the administrator of the library who are going to interact with the system and not the customers. – Fth Oct 29 '16 at 10:39

1 Answers1

1

You need a class library for each layer under your application. You can do as you say and compile the class to get a dll then add the DLL as a reference, however to simplify, add a project reference to each of the class library projects... The compiler will then take care of the DLL references when you build it.

Theo
  • 885
  • 6
  • 16
  • I would argue that the "layers" is an abstract concept, could be achieved by anything from different classes (defined in different packages as the requirements demand) to different project dll's (or even application/processes) - the idea is the layers need to be loosely coupled and focus on certain responsibilities, this would be modules that can be reused, tested independently, modified without affecting other parts of the system etc. – brakeroo Oct 28 '16 at 19:22
  • I'll buy your argument, however the question states "Then i have to implement the business logic as a .dll (library)." implying that at least one of the layers (business logic layer) is a separate class library I merely extended that to imply that the 3rd layer (one assumes is probably data access) is again a separate class library - but as you point out it doesn't have to be. – Theo Oct 28 '16 at 19:28
  • Yes, both business logic and data access layers have to be class libraries, but right now i don't have to implement the data access layer. When looking at the answers, it looks like the best solution is to create a project for each layer, so i will try this approach. – Fth Oct 29 '16 at 10:01