Project
Keep current project in tact. This is similar in practice as applying the strangler pattern. Doing so will keep the project as a point of reference. More importantly, it keeps the compiler happy and allows for porting each project independently. When selecting the project, always start with the core project (i.e. one with the least to no dependency).
Preserve project name and namespace. When creating the project, keep the project name and namespace the same. Do choose a new folder to create the project in. This could be as simple as naming the folder port
. If you choose to create a Visual Studio solution folder, make sure it does not end up in the namespace.
Create an equivalent project under the .NET Core template. For a Console project create the equivalent Console Core project. Doing this step will create an empty project with a .NET Core template. Mainly the csproj
XML structure.
Wire up with DI
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.IO;
class Program
{
protected static IHost _host;
static void Main(string[] args)
{
_host = CreateHostBuilder(args).Build();
foreach (string arg in args)
{
switch (arg)
{
case "Product":
_host.Services.GetService<ProductClass>().Run();
break;
case "Price":
_host.Services.GetService<PriceClass>().Run();
break;
}
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureHostConfiguration(configHost =>
{
configHost.SetBasePath(Directory.GetCurrentDirectory());
configHost.AddJsonFile("appsettings.json", optional: true);
configHost.AddEnvironmentVariables(prefix: "MyApp_");
configHost.AddCommandLine(args);
}).ConfigureServices(services =>
{
services.AddScoped<ProductClass>();
services.AddScoped<PriceClass>();
});
}
public class ProductClass
{
public void Run()
{
// Add logic here.
}
}
public class PriceClass
{
public void Run()
{
// Add logic here.
}
}