question

BrianBernholtz-2175 avatar image
0 Votes"
BrianBernholtz-2175 asked DuaneArnold-0443 answered

Migrating N Tier Framework 4.7.2 Web API stack to NET Core

We have a number of applications that utilize a similar stack on NET 4.7.2

  • Web API 2.0 : REST pattern

  • Business

  • Data : Generic Repo Pattern, EF 6.4, Database First, Audit (using EF 6 change tracking)

Does anyone have some guidance/best practices on getting us to NET Core 5.

For example, I have seen it is possible to go to keep EF6 and use Core 3.1. Are there any caveats to this?

Thanks!

dotnet-aspnet-core-webapi
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered

@BrianBernholtz-2175

IMHO, if you going to migrate to .NET Core, then you should go all the away to .NET 5 and EF 5.

ASP.NET WebAPI uses the MVC pipeline, and the VS project folder structure is the same in regards to the Models folder where domain/business objects reside that can be dependency injected into a controller.

https://deviq.com/terms/kinds-of-models

The generic repository pattern I am not too fond of it and it's too generic, it's not flexible, it shouldn't be doing data persistence, the EF DBContext is already using the UOW and repository pattern and repeating the pattern over EF is not optimal.

https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontext?view=efcore-5.0

https://www.thereformedprogrammer.net/is-the-repository-pattern-useful-with-entity-framework-core/

The repository pattern is a domain pattern by domain and not a data persistence pattern.

https://programmingwithmosh.com/net/common-mistakes-with-the-repository-pattern/

But anyway, you're using the pattern, and I am ranting. :)

For an existing database and using EF Core, you can scaffold against the existing database to build the DBcontext, which should be DI into the generic Repository class. and the connectionstring DI into the DBContext. Also there is the EF tools that allows on the reverse engineer the DBcontext and build the EF Core model from a graphical UI interface in selecting the tables that is similar to the EF 6 DB first graphical UI for model creation.

There is no more EDMX in EF Core.

.NET Core is big on using an IoC its IoC called Services and DI.

https://ardalis.com/new-is-glue/

https://www.c-sharpcorner.com/blogs/understanding-interfaces-via-loose-coupling-and-tight-coupling

https://docs.microsoft.com/en-us/archive/msdn-magazine/2016/may/asp-net-writing-clean-code-in-asp-net-core-with-dependency-injection

https://docs.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/architectural-principles

You can make the Core WebAPI project and all other Core projects needed and copy the classes needed form the .NET 4.7 project to the .NET Core project. It going to come down to remodeling some namespaces from classes and adding some namespaces to classes for the most part in doing a conversion IMHO.

Here is a Core MVC project using Core WebAPI and EE in the DAL using the DTO and DAO patterns you can examine.

https://javarevisited.blogspot.com/2013/01/data-access-object-dao-design-pattern-java-tutorial-example.html

https://docs.microsoft.com/en-us/aspnet/web-api/overview/data/using-web-api-with-entity-framework/part-5

https://github.com/darnold924/PubCompanyCore3.x


HTH

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.