Add initial database context and first entity
This commit is contained in:
36
Program.cs
36
Program.cs
@@ -1,8 +1,31 @@
|
||||
using Diary.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
//GetConfigStuff
|
||||
IConfigurationRoot? config = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json",false)
|
||||
.Build();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
builder.Services
|
||||
.AddDbContext<DiaryDBContext>(opt =>
|
||||
{
|
||||
string connectionString = config.GetConnectionString("Diary");
|
||||
opt.UseSqlServer(connectionString);
|
||||
});
|
||||
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddDbContext<DiaryDBContext>();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddScoped<IDiaryDBContext, DiaryDBContext>();
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
@@ -12,8 +35,13 @@ var app = builder.Build();
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(opt =>
|
||||
{
|
||||
opt.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
|
||||
opt.RoutePrefix = String.Empty;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
@@ -22,4 +50,4 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user