-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (42 loc) · 1.91 KB
/
Copy pathProgram.cs
File metadata and controls
50 lines (42 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using ETL.Orders.BLL;
using ETL.Orders.DAL;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace ETL.Orders;
public class Program
{
static async Task Main(string[] args)
{
if(args.Length == 0)
{
Console.WriteLine("Please provide the path to the data.xml file as an argument.");
return;
}
var filePath = args[0];
if(!File.Exists(filePath))
{
Console.WriteLine($"The file '{filePath}' does not exist.");
return;
}
var environment = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Development";
var configuration = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile($"appsettings.{environment}.json", optional: false, reloadOnChange: true)
.Build();
var services = new ServiceCollection();
services.AddLogging(builder => { builder.AddConsole(); builder.AddDebug(); });
services.AddDbContext<InternetStoreContext>(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));
services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<IProductRepository, ProductRepository>();
services.AddScoped<IPurchaseItemRepository, PurchaseItemRepository>();
services.AddScoped<IPurchaseRepository, PurchaseRepository>();
services.AddScoped<PurchaseService>();
services.AddSingleton<IFileProcessingService, XmlFileProcessingService>();
var serviceProvider = services.BuildServiceProvider();
var fileProcessing = serviceProvider.GetRequiredService<IFileProcessingService>();
await fileProcessing.ProcessFile(filePath);
Console.WriteLine("Process file is successful complete.");
}
}