0

I recently built an MVC web project in .Net Core for which I now want to build an Android and iOS front end. I understand the differences between .Net Standard and .Net Core, but am having a problem figuring out what should go in which project. First I'll describe the current solution:

enter image description here

DataModel: As you would expect, DataModel contains all of my base models and DTOs. It is referenced by all other projects.

DataAccess: Performs all data storage/acquisition operations (repositories) and references only DataModel

HostService: RESTful service which serves up data and references DataModel and DataAccess

Display: Front end MVC code that contains ViewModels, Views, Controllers, etc and references DataModel and HostService

It is my understanding that some portions of the Display project really need to be in a .Net Standard project in order to reuse them in an Xamarin project targeting Adroid and iOS, but I am a bit confused as to what parts should move to the new .Net Standard project. Obviously the Views will need to stay in the Display project as they contain Razor code specific to the web front end. It would appear to me that the only things that need to be moved to the new project are ViewModels and Controllers (as well as anything they reference)? Does this sound right or am I over simplifying it? Am I missing something or are there any gotchas I should know about?

FWIW, I ran the .Net portability Analyzer and received these results: enter image description here

It notated that these items were not compatible with .Net Standard: enter image description here

How do I determine where these conflicts occur to resolve them? I looked for the target members (IE. Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute) in the Display project but didn't find any matches, so I am uncertain on how to fix them. Any pointers would be greatly appreciated!

Aaron Bar
  • 611
  • 1
  • 7
  • 20
  • please visite https://stackoverflow.com/questions/42939454/what-is-the-difference-between-net-core-and-net-standard-class-library-project/42940138 – jayesh dhameliya Sep 30 '19 at 07:00

1 Answers1

0

For those that arrived at this question looking to do the same thing, here are the results of my further research.

The simple answer is you can't.

The long answer:

My web code is written using MVC (Model-View-Controller) whereas Xamarin uses MVVM (Model-View-View Model). The two infrastructures are incompatible. They both share a common model, but that is where the similarities end.

In MVC, a view requests an action from the controller. The controller then retrieves data from the model, creating any necessary data structures needed to compose the view, then returns the view which uses the data structures to display the view. The data structures can either be a stand alone item such as List< Employee > or a ViewModel that contains many fields List< Employee > Employees, int CurrentEmployeeID, string CurrentEmployeeName, etc. This ViewModel is simply a temporary storage device used to transport data between the controller and the view and contains no business logic.

In MVVM on the other hand, the ViewModel takes the place of the controller. A view requests an action from the ViewModel. The ViewModel then performs the requested action (retrieveing data from the model) and stores the data within itself calling INotifyProperty. The View has a listener for PropertyChanged and when it recieves event notification from the ViewModel, it requests the updated data from the ViewModel.

So while, both infrastructures (can) use something called a ViewModel, they operate VERY differently and can not be shared across code bases. In the above scenario, the only code that will be shared is from the HostService (model) down. None of the code from PVS.Display will be reusable in my Xamarin project.

Aaron Bar
  • 611
  • 1
  • 7
  • 20