Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get wwwroot path when in ConfigureServices (aspnetcore)

In my aspnetcore app (v2.1) I need to configure a read-only database (entityframework core + SQLite) which is in ~/wwwroot/App_Data/quranx.db

I need to call this code in Startup.ConfigureServices

services.AddDbContext<QuranXDataContext>(options => options
    .UseSqlite($"Data Source={databasePath}")
    .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
);

But at that point I cannot find a way to get the path to wwwroot. To get that path I need IHostingEnvironment, but I am unable to get a reference to that until Startup.Configure is called, and that is after Startup.ConfigureServices has finished.

How is this done?

like image 744
QuranX Administrator Avatar asked Aug 27 '18 13:08

QuranX Administrator


1 Answers

Path.GetFullPath("wwwroot");

like image 149
Atif Avatar answered Sep 26 '22 02:09

Atif