How to migrate a C# system using ASP.NET?

Asked

Viewed 221 times

1

Good morning! I’m new to the programming environment and I’m developing a C# system using Windows Forms. In the future I intend to make this same system in ASP.NET. I wonder if there is any way to make the most of the code already made in the project forms and classes and migrate them to the project in ASP.NET.

  • 4

    separate all that is Forms from what is business layer and data

  • Also take advantage to extract everything that is in your form, in the oriented programming and button and transport these fuctionalities to the business layer tbm

1 answer

1

Layers

The solution you’re looking for is known as layered architecture. When you separate your system into layers you are looking for some advantages like independence and reuse. What is the main disadvantage? More work to build and more code "duplicity".

A popular layer model is the 3 layer model, where you have the presentation layer, the business layer and the data layer. Each has a well-defined goal and this allows you to make the "exchange" of one layer without having to rewrite the other. Realize that this is a logical separation and does not always mean a physical separation.

In theory, this means that each layer will be completely independent and for this to work you need to work with the concept of "interfaces". This means that the communication between one layer and the other needs to be very clear and defined for the two ends that will communicate. Then you will have interfaces between the business layer and data and another set between the presentation layer and the business layer.

Having the business layer does not mean that you will always have business rules applied to the data, but it is necessary that the communication between the presentation layer and the data layer does not occur directly, without going through, even without any change by the business layer.

That article can give an introduction to this subject.

In your case, you are creating your presentation layer using Windows Forms. The other parts of the system should not have any dependency on this technology, that is, if any business class or data access cannot be removed from the Windows Forms project and run in a "Console" project, for example, its layers will not be well separated.

In a practical way, working in the 3 layers means that you wouldn’t have any code with business rules or a database connection within forms. In order for the form to save its data, it would need to pass this data through an interface known to both layers. The same should occur between the business layer and the data layer. It is also very common for systems to leave the business layer coupled with the data layer when there is no concern to change database provider, for example, but as I said at the beginning, it is always a matter of choice that will bring you advantages and disadvantages.

Regarding your concern to reuse as much code as is in the forms, if you have already separated those parts above, the next step would be for you to choose or develop a technology that can generate your forms from a set of metadata. This metadata-based architecture allows you to generate forms from some declarative information, something like the XAML. You can use something ready or build your own. The central idea is that from these metadata you would be able to create your forms for both Windows Forms and the Web.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.