Search code examples
winformsweb-applicationsmodelssharing

Best approach for sharing data layer and model layer between winforms and web app


I am currently developing an ERP solution for a company. The requirements are as below :

  1. They need one winforms based application which will take care of modules like HR, BSC, Inventory etc.

  2. A web based solution that needs all employees to get access to their personal data, apply for leave etc. This needs to be an internet based solution which can be accessed from anywhere.

  3. In future they also want a document management system which will be web based.

Right now we are already through with some modules in winforms application as that was the urgent requirement. For winforms we have taken a horizontal approach for layered architecture. i.e. each module is one project with its own datalayer and businesslayer within project. Now I need to start working on the web solution. I am just wondering which approach will be best approach to share the datalayer and model layer between the winforms app and web app. Also the web app needs to have proper security in place as it will be sensitive data. I have thought about 2 approaches which may not cover all possibilities available.

The approaches I can think of are as below :

a. make a web service which will take care of datalayer and models. host it on the server and access it through winforms app and web app. For this I will need to change the coding that I have already done. But it is acceptable as it will require minimum efforts as its a layer architecture. here the only doubt I have is, for winforms app it will unnecessarily go through the web service layer and make it slower.

b. Convert the datalayer and models into dlls. Access these dlls in winforms and web app.

Also regarding the web app which will be the better approach :

a. Should I go for MVC3 based web app.

b. OR asp.net and WCF?

The situation is that I am working on this project along with a colleague and we are the team of just 2. So we are the ones taking decisions about everything.

I have fairly good experience in winforms but comparatively less experience in web based technologies. I will really appreciate your opinions on this.


Solution

  • If you want your model types to correspond closely to your database schema, you could create them using the Entity Framework designer and the Self-Tracking Entities template. This will allow them to be easily serialized with changes via WCF and persisted to and from the database. You then have the option of either creating a custom WCF service to deal with the entities or could exposing your Entity Framework context directly as a service using WCF Data Services (OData).

    As far as the presentation layer goes, the two choices you listed are not mutually exclusive. You can have MVC with WCF, MVC without WCF, WebForms with WCF, WebForms without WCF... Since you are going to need to create the service anyway, and MVC seems like the way to go these days, I would probably recommend an MVC application that uses your WCF service to access the data.