48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using StockHistory.Data;
|
|
using StockHistory.Services;
|
|
|
|
namespace StockHistory
|
|
{
|
|
internal static class Program
|
|
{
|
|
/// <summary>
|
|
/// The main entry point for the application.
|
|
/// </summary>
|
|
[STAThread]
|
|
static void Main()
|
|
{
|
|
var host = CreateHostBuilder().Build();
|
|
|
|
using (var scope = host.Services.CreateScope())
|
|
{
|
|
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
|
db.Database.Migrate(); // skapar databasen om den saknas
|
|
}
|
|
|
|
// To customize application configuration such as set high DPI settings or default font,
|
|
// see https://aka.ms/applicationconfiguration.
|
|
ApplicationConfiguration.Initialize();
|
|
// Starta huvudformuläret via DI
|
|
var mainForm = host.Services.GetRequiredService <frmStockHistoryInit>();
|
|
Application.Run(mainForm);
|
|
}
|
|
static IHostBuilder CreateHostBuilder() =>
|
|
Host.CreateDefaultBuilder()
|
|
.ConfigureServices((context, services) =>
|
|
{
|
|
services.AddDbContext<AppDbContext>(options =>
|
|
options.UseSqlite("Data Source=Stockbrokerage.db"),
|
|
ServiceLifetime.Transient);
|
|
|
|
services.AddSingleton<frmStockHistoryInit>();
|
|
services.AddTransient<IPdfOpener, PdfOpener>();
|
|
services.AddTransient<IPdfFormatter, PdfFormatter>();
|
|
services.AddTransient<ITransactionNotesServices, TransactionNotesServices>();
|
|
services.AddTransient<IHandleCsvNotes, HandleCsvNotes>();
|
|
});
|
|
|
|
}
|
|
} |