Working on BackgroundService
This commit is contained in:
parent
9f4996bc8f
commit
ad4ed12f00
12 changed files with 368 additions and 317 deletions
|
|
@ -6,6 +6,10 @@
|
|||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Database\PlanTempus.Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Autofac;
|
||||
using Insight.Database;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using PlanTempus.Database.ConfigurationManagementSystem;
|
||||
using PlanTempus.Database.Core.DCL;
|
||||
using PlanTempus.Database.Core.DDL;
|
||||
|
|
@ -189,5 +190,35 @@ namespace PlanTempus.SetupInfrastructure
|
|||
Console.ForegroundColor = ConsoleColor.White;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async Task Run(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = Host.CreateDefaultBuilder(args)
|
||||
.UseServiceProviderFactory(new Autofac.Extensions.DependencyInjection.AutofacServiceProviderFactory())
|
||||
.ConfigureContainer<ContainerBuilder>((hostContext, builder) =>
|
||||
{
|
||||
var startup = new Startup();
|
||||
var connectionStringParams = new Startup.ConnectionStringTemplateParameters("your_user", "your_password");
|
||||
startup.ConfigureContainer(connectionStringParams);
|
||||
})
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
// Konfigurer andre services her (hvis nødvendigt)
|
||||
})
|
||||
.Build();
|
||||
|
||||
await host.StartAsync();
|
||||
Console.WriteLine("Host has started.");
|
||||
await host.WaitForShutdownAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Host failed to start: {ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,41 +6,47 @@ using PlanTempus.Database.Core;
|
|||
|
||||
namespace PlanTempus.SetupInfrastructure
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public virtual IConfigurationRoot Configuration()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.json")
|
||||
.Build();
|
||||
public class Startup
|
||||
{
|
||||
public virtual IConfigurationRoot Configuration()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.json")
|
||||
.Build();
|
||||
|
||||
return configuration;
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public IContainer ConfigureContainer(ConnectionStringTemplateParameters ctp)
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
var configuration = Configuration();
|
||||
public IContainer ConfigureContainer(ConnectionStringTemplateParameters ctp)
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
var configuration = Configuration();
|
||||
|
||||
|
||||
builder.RegisterModule(new Database.ModuleRegistry.DbPostgreSqlModule
|
||||
{
|
||||
ConnectionString = configuration.GetConnectionString("DefaultConnection").Replace("{usr}", ctp.user).Replace("{pwd}", ctp.pwd)
|
||||
});
|
||||
builder.RegisterModule(new Database.ModuleRegistry.DbPostgreSqlModule
|
||||
{
|
||||
ConnectionString = configuration.GetConnectionString("DefaultConnection").Replace("{usr}", ctp.user).Replace("{pwd}", ctp.pwd)
|
||||
});
|
||||
|
||||
builder.RegisterModule(new TelemetryModule
|
||||
{
|
||||
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<TelemetryConfig>()
|
||||
});
|
||||
builder.RegisterModule(new TelemetryModule
|
||||
{
|
||||
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<TelemetryConfig>()
|
||||
});
|
||||
|
||||
builder.RegisterAssemblyTypes(typeof(IDbConfigure<>).Assembly)
|
||||
.AsClosedTypesOf(typeof(IDbConfigure<>))
|
||||
.AsSelf();
|
||||
builder.RegisterModule(new SeqLoggingModule
|
||||
{
|
||||
SeqConfiguration = configuration.GetSection("SeqConfiguration").ToObject<Core.Logging.SeqConfiguration>()
|
||||
});
|
||||
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
builder.RegisterAssemblyTypes(typeof(IDbConfigure<>).Assembly)
|
||||
.AsClosedTypesOf(typeof(IDbConfigure<>))
|
||||
.AsSelf();
|
||||
|
||||
public record ConnectionStringTemplateParameters(string user, string pwd);
|
||||
}
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
public record ConnectionStringTemplateParameters(string user, string pwd);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
{
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id={usr};Password={pwd};"
|
||||
},
|
||||
"ApplicationInsights": {
|
||||
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
|
||||
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/",
|
||||
"UseSeqLoggingTelemetryChannel": true
|
||||
},
|
||||
"SeqConfiguration": {
|
||||
"IngestionEndpoint": "http://localhost:5341",
|
||||
"ApiKey": null,
|
||||
"Environment": "MSTEST"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue