Search code examples
c#.net-coreservicearchitecture3-tier

When Moving from .NET 4.x to .NET Core 7 should I change the UserManager class to a UserService and in Program.cs and do AddScoped<UserService> etc


I am moving from .NET 4.x to .NET Core 7 and in the 4.x project I have a 3-Tier architecture; BLL, DAL, UI. In my BLL I have managers like UserManager, BasketManager etc.

I am trying to understand what should change in order to take advantage of the .NET Core 7 performance gains through it's architecture, and basically code the .NET Core 7 way.

Fundamentally, should these managers be changed to services so that they are added in the Program.cs using AddScoped?

I have read a lot of the .NET Core 7 documentation but have not seen any examples where I can see a .NET 4.x application and then see what that same application looks like when migrated to .NET Core 7.


Solution

  • Assuming UserManager, BasketManager etc are custom classes, then you should be able to keep them just as they are when migrating to .net core. Unless you are using the deprecated APIs, your .net framework code should work fine in .Net 7. But it really depends on your type of application and what dependencies you have.

    The AddScoped is part of a "Dependency injection" framework, Microsoft.Extensions.DependencyInjection. Asp.net core applications uses this by default, so you might want to rewrite your asp.net application to follow the new model to keep things simple and consistent. See Upgrade from ASP.NET Framework to ASP.NET Core for details.

    But you can also use Dependency injection in desktop applications, even .net framework applications. I tend to like using Dependency injection, but it can be difficult to retrofit an existing application to use it. But desktop applications do not force you to use any specific architecture, so it is probably easier to make as few changes as possible when migrating, and introduce dependency injection as a separate change.