Created
April 17, 2025 17:04
-
-
Save joe-oli/7b5d655c49a07f315f599ff0bd1512ec to your computer and use it in GitHub Desktop.
dotnet Program.cs example (no Startup.cs required)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Blog.EFLayer.Models; | |
using Microsoft.EntityFrameworkCore; | |
using Jolisoft.Common.Logging; //AddFileLogger | |
namespace Blog.Api; | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var builder = WebApplication.CreateBuilder(args); | |
//1). Add services to the container. | |
builder.Services.AddControllers(); | |
builder.Services.AddOpenApi(); | |
builder.Services.AddDbContext<BlogDbCtx>( | |
options => options.UseNpgsql(builder.Configuration.GetConnectionString("PostgresCnnStr")) | |
); | |
builder.Logging.AddFileLogger(builder.Configuration); | |
var app = builder.Build(); | |
//2). Configure the HTTP request pipeline. | |
if (app.Environment.IsDevelopment()) | |
{ | |
app.MapOpenApi(); | |
} | |
app.UseHttpsRedirection(); | |
app.UseAuthorization(); | |
app.MapControllers(); | |
app.Run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment