EdwinVW/pitstop

Questions regarding - Upgrade to .NET Core 3.0

CodeWithKashif opened this issue · 4 comments

Hi @EdwinVW

I have a question around one of your old commit i.e. related to Upgrade to .NET Core 3.0 c8db950

Here I am not sure, why have you removed AutoMapper reference and instead you have added your own Mappers class under Pitstop.WorkshopManagementAPI.Mappers namespace.


Actually I was using the older version of Pitstop that was on .net core 2.2 and I was trying to migrate that locally on my machine to .net core 3.1

I am able to migrate all the projects successfully however something weird was happening with WorkshopManagementAPI.WorkshopPlanningController where PlanMaintenanceJobAsync action was not being called in migrated project(core 3.1). and probably PlanMaintenanceJob command was causing some kind of issue.

So I have gone through all your changes and I replicated your approach where I have also removed AutoMapper and make use of your new class, which has solved my problem.

However I am still not very much sure what was the actual root cause and how is it fixing this problem.
Kindly help sir.

The latest version of Pitstop runs on .NET 5. So I suggest you use the latest version. I will upgrade to .NET 6 once this is GA.

Regarding AutoMapper: I think AutoMapper is a great library, but based on some real world projects, I now prefer writing the mappings manually The mappings in Pitstop are very simple for now. But even if I would need to do complex mappings in the future, I'd still rather write these manually than having to configure them using AutoMapper. I have seen too much projects start out simple with AutoMapper and after some time had very complex AutoMapper configurations. The biggest problem with that is that they were hard to understand and troubleshoot for the developers. Also see this blog article for more information on some issues that can arise when using AutoMapper.

But again I want to explicitly stress that this is my personal preference and there is nothing wrong with the quality of the library. Just use it with care and make sure it fits your use-case (as with every library by the way!).

Hope this helps.

Thanks a lot for detailed answer!
Yes I would be start using pitstop later version shortly as I see some great exciting things has been added like value objects etc.
Yeah I am fully align with your thoughts around Automapper too.

One last question - did you also encountered similar issue after migrating to .net core 3.0 as i mentioned earlier PlanMaintenanceJobAsync action was not being called from webapp or from postman too

I guess is has something to do with JSON serialization. With .NET Core 3, the default JSON serializer used by ASP.NET Core was changed from the NewtonSoft.Json serializer to the System.Text.Json serializer. The last one does not support polymorphism. But all Pitstop commands derive from the Command base-class. Because of this, not all properties of the PlanMaintenanceJob command are serialized when sent to the WebAPI. Therefore the ASP.NET Core model binding mechanism is not able to map the incoming JSON payload to the PlanMaintenanceJob type. So no corresponding API operation can be determined.

If you examine commit c8db950 and look in the ConfigureServices method of the WebAPIs, you can see I explicitly specify to use the NewtonSoft.Json serializer:

services
  .AddMvc(options => options.EnableEndpointRouting = false)
  .AddNewtonsoftJson();

The last one does not support polymorphism. But all Pitstop commands derive from the Command base-class.

Ah! Sir you are right on the money as it was working fine when I removed the base class(Command) inheritance

Now I got it why you had used this one:

services
  .AddMvc(options => options.EnableEndpointRouting = false)
  .AddNewtonsoftJson();

You made my day! Thanks a lot again 👍