Skip to content

Instantly share code, notes, and snippets.

@talkingdotnet
Created February 27, 2018 05:55
Show Gist options
  • Save talkingdotnet/d4cc22a85570c23ef2225e4263abb65b to your computer and use it in GitHub Desktop.
Save talkingdotnet/d4cc22a85570c23ef2225e4263abb65b to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
var services = new ServiceCollection();
ConfigureServices(services);
var provider = services.BuildServiceProvider();
Console.WriteLine("** Welcome to Data Transfer tool **");
Console.WriteLine("** Please select one of the following option **");
Console.WriteLine("** [1] - Enter 1 for extracting data from SQL Server Data **");
Console.WriteLine("** [2] - Enter 2 for inserting data in MySQL Database **");
var input = Console.ReadLine();
try
{
switch (input)
{
case "1":
var deService = provider.GetRequiredService<DataExtractor>();
deService.ExtractData();
break;
case "2":
var mySQLService = provider.GetRequiredService<MySQLDataImport>();
mySQLService.Import();
break;
default:
break;
}
Console.WriteLine("** Process Completed.. Press any key to exit. **");
}
catch (Exception ex)
{
Console.WriteLine("** Exception Occured.. **");
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}
private static void ConfigureServices(IServiceCollection serviceCollection)
{
serviceCollection.AddTransient<DataExtractor>();
serviceCollection.AddTransient<MySQLDataImport>();
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsetting.json", false)
.Build();
serviceCollection.AddSingleton<IConfigurationRoot>(configuration);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment