C#
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using CarManagementSystem.Infrastructure.Data;
using CarManagementSystem.Application.Services;
using CarManagementSystem.Core.Interfaces;
using CarManagementSystem.Infrastructure.Repositories;
using CarManagementSystem.Core.Entities;
using CarManagementSystem.Helpers;
Console.WriteLine(Guid.NewGuid().ToString());
/*var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
// Register DbContext
services.AddDbContext<CarContext>(options =>
options.UseSqlServer("REAL CONNECTION STRING HOWEVER OUT-COMMENTED"));
// Register repositories and services
services.AddScoped<ICarRepository, CarRepository>();
services.AddScoped<CarService>();
})
.Build();
// Rest of your code remains unchanged
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
try
{
var CarService = services.GetRequiredService<CarService>();
// Example usage of the CarService
var Car = new Car
{
SerialNumber = Guid.NewGuid(),
ModelId = "",
ModelName = "",
Manufacturer = "",
PrimaryUser = "",
CarType = CarType.SUV,
Status = CarStatus.Active
};
CarService.AddCar(Car);
var activeCars = CarService.GetActiveCars();
foreach (var d in activeCars)
{
Console.WriteLine($"{d.ModelName} - {d.Status}");
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
await host.RunAsync();*/