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:
@@ -19,20 +19,13 @@ public class DataContext : DbContext
|
||||
/// </summary>
|
||||
public DbSet<Track> Tracks { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DataContext() : base() {}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DataContext(DbContextOptions<DataContext> options) : base(options) {}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="DataContext"/>.
|
||||
/// </summary>
|
||||
/// <param name="options">The options for this context.</param>
|
||||
public DataContext(DbContextOptions<DataContext> options) : base(options)
|
||||
{
|
||||
optionsBuilder
|
||||
.UseSqlite("Data Source=data.db")
|
||||
.EnableSensitiveDataLogging(
|
||||
Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development"
|
||||
);
|
||||
Database.Migrate();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MuiCharts.Domain.Repositories;
|
||||
using MuiCharts.Infrastructure.Repositories;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace MuiCharts.Infrastructure;
|
||||
|
||||
@@ -14,12 +17,16 @@ public static class InfrastructrureExtensions
|
||||
/// </summary>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
|
||||
/// <returns>The modified <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection AddInfrastructure(this IServiceCollection services)
|
||||
public static void AddInfrastructure(this IHostApplicationBuilder builder)
|
||||
{
|
||||
services.AddDbContext<DataContext>();
|
||||
services.AddScoped<IPointRepository, PointRepository>();
|
||||
services.AddScoped<ITrackRepository, TrackRepository>();
|
||||
builder.Services.AddDbContext<DataContext>(options =>
|
||||
{
|
||||
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>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" 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>
|
||||
|
||||
Reference in New Issue
Block a user