I've created three new .NET 7 projects:
- API
- Database
- Worker
In my Database project, I have my DbContext set up. The API and Worker project both have a project reference to the Database project.
In my API project (using minimal hosting model), I simply configure the database connection like this:
var builder = WebApplication.CreateBuilder(args);
....
....
....
builder.Services.AddDbContext<EnergyPricesContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))
);
However, my Worker project is a console application, so I cannot simply do the above line, because there is no builder, no dependency injection, and there is also no appsettings.json file in that project.
I thought about creating a bootstrap project, which would have the appsettings.json file as well as a "Startup" file that all projects have a reference to. However, I feel like that's a bad idea.
What's best practise when it comes to multiple projects and referencing the same appsetting.json file, if that's even the correct way to do it?