mirror of
https://github.com/XFox111/MuiCharts.git
synced 2026-04-22 06:51:05 +03:00
- Reworked Infrastructure injection
- Added LettuceEncrypt for HTTPS - Fixed DataContext - Moved connection string to appsettings.json
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="LettuceEncrypt" Version="1.3.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using LettuceEncrypt;
|
||||||
using MuiCharts.Infrastructure;
|
using MuiCharts.Infrastructure;
|
||||||
|
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -17,7 +18,8 @@ WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
|||||||
{
|
{
|
||||||
options.SuppressAsyncSuffixInActionNames = false;
|
options.SuppressAsyncSuffixInActionNames = false;
|
||||||
});
|
});
|
||||||
builder.Services.AddInfrastructure();
|
|
||||||
|
builder.AddInfrastructure();
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen(options =>
|
builder.Services.AddSwaggerGen(options =>
|
||||||
@@ -26,6 +28,10 @@ WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
|||||||
string xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFileName);
|
string xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFileName);
|
||||||
options.IncludeXmlComments(xmlPath);
|
options.IncludeXmlComments(xmlPath);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (builder.Configuration.GetSection("LettuceEncrypt").Exists())
|
||||||
|
builder.Services.AddLettuceEncrypt()
|
||||||
|
.PersistDataToDirectory(new DirectoryInfo("/persistence"), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
WebApplication app = builder.Build();
|
WebApplication app = builder.Build();
|
||||||
@@ -35,7 +41,9 @@ WebApplication app = builder.Build();
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
|
|
||||||
// app.UseHttpsRedirection();
|
if (app.Configuration.GetSection("LettuceEncrypt").Exists())
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
@@ -4,5 +4,8 @@
|
|||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DataContext": "Data Source=app.db"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,8 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DataContext": "Data Source=/persistence/data.db"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,20 +19,13 @@ public class DataContext : DbContext
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DbSet<Track> Tracks { get; set; }
|
public DbSet<Track> Tracks { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <summary>
|
||||||
public DataContext() : base() {}
|
/// Initializes a new instance of <see cref="DataContext"/>.
|
||||||
|
/// </summary>
|
||||||
/// <inheritdoc/>
|
/// <param name="options">The options for this context.</param>
|
||||||
public DataContext(DbContextOptions<DataContext> options) : base(options) {}
|
public DataContext(DbContextOptions<DataContext> options) : base(options)
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
||||||
{
|
{
|
||||||
optionsBuilder
|
Database.Migrate();
|
||||||
.UseSqlite("Data Source=data.db")
|
|
||||||
.EnableSensitiveDataLogging(
|
|
||||||
Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using MuiCharts.Domain.Repositories;
|
using MuiCharts.Domain.Repositories;
|
||||||
using MuiCharts.Infrastructure.Repositories;
|
using MuiCharts.Infrastructure.Repositories;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace MuiCharts.Infrastructure;
|
namespace MuiCharts.Infrastructure;
|
||||||
|
|
||||||
@@ -14,12 +17,16 @@ public static class InfrastructrureExtensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
|
||||||
/// <returns>The modified <see cref="IServiceCollection"/>.</returns>
|
/// <returns>The modified <see cref="IServiceCollection"/>.</returns>
|
||||||
public static IServiceCollection AddInfrastructure(this IServiceCollection services)
|
public static void AddInfrastructure(this IHostApplicationBuilder builder)
|
||||||
{
|
{
|
||||||
services.AddDbContext<DataContext>();
|
builder.Services.AddDbContext<DataContext>(options =>
|
||||||
services.AddScoped<IPointRepository, PointRepository>();
|
{
|
||||||
services.AddScoped<ITrackRepository, TrackRepository>();
|
options
|
||||||
|
.UseSqlite(builder.Configuration.GetConnectionString(nameof(DataContext)))
|
||||||
|
.EnableSensitiveDataLogging(builder.Environment.IsDevelopment());
|
||||||
|
});
|
||||||
|
|
||||||
return services;
|
builder.Services.AddScoped<IPointRepository, PointRepository>();
|
||||||
|
builder.Services.AddScoped<ITrackRepository, TrackRepository>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.1" />
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user