How to share the most code between a WPF and an ASP.NET MVC application?

后端 未结 7 1731
野性不改
野性不改 2021-02-19 06:20

What architecture and patterns can I use to share the most model and logic code between a WPF and an ASP.NET MVC application?

I am trying to achieve a bit more here than

7条回答
  •  深忆病人
    2021-02-19 06:57

    Create a service layer for your application by specifying interfaces with methods that represent all of the operations you need to perform. Also, in this service layer, define all of the data types used by the application. Those data type classes should contain only properties, not operations. Put these interfaces and classes in an assembly all by itself. This assembly should be shared between your web app, WPF app, and the code that implements it.

    Finally once you have this separation, you can freely develop the application's internal structure, and leave the responsibility of UI operations (e.g. what happens when you click xyz button) to the respective UI.

    As an aside, you can expose your service layer, via WCF and web services. You can use this to make call from the web browser via javascript. You could do things like client-side validation or even look up values on the fly for drop down population. all while reusing it between your two application.

提交回复
热议问题