Search code examples
.netportable-class-libraryuwp

Is it possible to share a middle-ware project between WPF and UWP 10 apps?


Say I've got a solution with the following projects:

Presentation layer:  ProjectA1 (UWP 10)    ProjectA2 (WPF)
                           ↓                   ↓
Infrastructure-mid:  ProjectM1 (UWP 10)    ProjectM2 (.NET 4.6)
                           ↓                   ↓
Infrastructure-low:  ProjectL1 (UWP 10)    ProjectL2 (.NET 4.6)

The presentation projects are definitely platform-specific, and so are the low-level infrastructure projects, as they take advantage of different UI and network technologies, respectively. But the mid-level infrastructure projects would be identical as they consist of plain internal logic.

Could the two mid-level projects be combined into one PCL, shared by both the UWP and WPF apps, like so:

Presentation layer:  ProjectA1 (UWP 10)    ProjectA2 (WPF)
                           ↓                   ↓
Infrastructure-mid:  ===========ProjectM (PCL)============
                           ↓                   ↓
Infrastructure-low:  ProjectL1 (UWP 10)    ProjectL2 (.NET 4.6)

..and then use dependency injection to get the appropriate low-level objects into the common mid-level components?


Solution

  • Yes. Using a PCL like this is a recommended practice to share code between the different targets.