Adds code
This commit is contained in:
commit
269bf50c78
33 changed files with 1489 additions and 0 deletions
52
Core/Configurations/ConfigurationManager.cs
Normal file
52
Core/Configurations/ConfigurationManager.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Core.Configurations
|
||||
{
|
||||
public class ConfigurationManager
|
||||
{
|
||||
private static IConfigurationBuilder _configurationBuilder;
|
||||
|
||||
/// <summary>
|
||||
/// This AppConfigBuilder assumes that AppConfigEndpoint and AppConfigLabelFilter are configured as Settings on Azure for the Application that needs them.
|
||||
/// AppConfigEndpoint would look like this: Endpoint=https://config-dec-test.azconfig.io;Id=0-l9-s0:foo;Secret=somesecret/bar
|
||||
/// </summary>
|
||||
/// <param name="localSettingsFile">
|
||||
/// Path relative to the base path stored in Microsoft.Extensions.Configuration.IConfigurationBuilder.Properties of builder.
|
||||
/// </param>
|
||||
public static IConfigurationBuilder AppConfigBuilder(string localSettingsFile)
|
||||
{
|
||||
if (_configurationBuilder == null)
|
||||
{
|
||||
var envConfiguration = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out));
|
||||
|
||||
var appConfigEndpoint = envConfiguration["AppConfigEndpoint"];
|
||||
var appConfigLabel = envConfiguration["AppConfigLabelFilter"];
|
||||
|
||||
_configurationBuilder = new ConfigurationBuilder();
|
||||
if (!string.IsNullOrEmpty(appConfigEndpoint))
|
||||
{
|
||||
_configurationBuilder
|
||||
.AddAzureAppConfiguration(options =>
|
||||
{
|
||||
options.Connect(appConfigEndpoint);
|
||||
options.Select(keyFilter: "*", labelFilter: appConfigLabel);
|
||||
})
|
||||
.AddEnvironmentVariables();
|
||||
}
|
||||
else
|
||||
{
|
||||
_configurationBuilder.SetBasePath(Directory.GetCurrentDirectory());
|
||||
_configurationBuilder.AddJsonFile(localSettingsFile, optional: false);
|
||||
}
|
||||
}
|
||||
return _configurationBuilder;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Core/Core.csproj
Normal file
26
Core/Core.csproj
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Akka" Version="1.5.32" />
|
||||
<PackageReference Include="Autofac" Version="8.1.1" />
|
||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="Insight.Database" Version="8.0.1" />
|
||||
<PackageReference Include="Insight.Database.Providers.PostgreSQL" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||
<PackageReference Include="npgsql" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Entities\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
9
Core/Exceptions/ConfigurationException.cs
Normal file
9
Core/Exceptions/ConfigurationException.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
namespace Core.Exceptions
|
||||
{
|
||||
internal class ConfigurationException : Exception
|
||||
{
|
||||
public ConfigurationException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Core/ModuleRegistry/DbPostgreSqlModule.cs
Normal file
22
Core/ModuleRegistry/DbPostgreSqlModule.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using Autofac;
|
||||
using Npgsql;
|
||||
using System.Data;
|
||||
namespace Core.ModuleRegistry
|
||||
{
|
||||
public class DbPostgreSqlModule : Module
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
|
||||
builder.Register(c =>
|
||||
{
|
||||
IDbConnection connection = new NpgsqlConnection(ConnectionString);
|
||||
return connection;
|
||||
})
|
||||
.InstancePerLifetimeScope();
|
||||
|
||||
//builder.RegisterType<IDbConnection>().As<IDbConnection>().InstancePerLifetimeScope();
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Core/ModuleRegistry/TelemetryModule.cs
Normal file
31
Core/ModuleRegistry/TelemetryModule.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using Autofac;
|
||||
|
||||
namespace Core.ModuleRegistry
|
||||
{
|
||||
public class TelemetryModule : Module
|
||||
{
|
||||
public TelemetryConfig TelemetryConfig { get; set; }
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
if (TelemetryConfig == null)
|
||||
throw new Exceptions.ConfigurationException("TelemetryConfig is missing");
|
||||
|
||||
var tmc = Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.CreateDefault();
|
||||
tmc.ConnectionString = TelemetryConfig.ConnectionString;
|
||||
tmc.TelemetryChannel.DeveloperMode = true;
|
||||
|
||||
//var r = new Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryProcessorChainBuilder(tmc);
|
||||
//r.Use(next => new Domain.EventTelemetryEnrichers.EnrichWithMetaTelemetry(next));
|
||||
//r.Build();
|
||||
|
||||
builder.RegisterInstance(tmc);
|
||||
builder.RegisterType<Microsoft.ApplicationInsights.TelemetryClient>().InstancePerLifetimeScope();
|
||||
}
|
||||
}
|
||||
|
||||
public class TelemetryConfig
|
||||
{
|
||||
public string InstrumentationKey { get; set; }
|
||||
public string ConnectionString { get; set; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue