Solution of warning
"Calling 'BuildServiceProvider' from application code results in an additional copy of singleton services being created. Consider alternatives such as dependency injecting services as parameters to 'Configure'"
This commit is contained in:
@ -25,13 +25,25 @@ namespace Oqtane.Infrastructure
|
||||
}
|
||||
|
||||
public void InstallPackages(string folders, bool restart)
|
||||
{
|
||||
var webRootPath = _environment.WebRootPath;
|
||||
|
||||
var install = UnpackPackages(folders, webRootPath);
|
||||
|
||||
if (install && restart)
|
||||
{
|
||||
RestartApplication();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool UnpackPackages(string folders, string webRootPath)
|
||||
{
|
||||
bool install = false;
|
||||
string binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
||||
|
||||
foreach (string folder in folders.Split(','))
|
||||
{
|
||||
string sourceFolder = Path.Combine(_environment.WebRootPath, folder);
|
||||
string sourceFolder = Path.Combine(webRootPath, folder);
|
||||
|
||||
// create folder if it does not exist
|
||||
if (!Directory.Exists(sourceFolder))
|
||||
@ -66,6 +78,7 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
frameworkversion = node.Attributes["version"].Value;
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
}
|
||||
@ -95,22 +108,21 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(filename));
|
||||
}
|
||||
|
||||
entry.ExtractToFile(filename, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove package
|
||||
File.Delete(packagename);
|
||||
install = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (install && restart)
|
||||
{
|
||||
RestartApplication();
|
||||
}
|
||||
return install;
|
||||
}
|
||||
|
||||
public void UpgradeFramework()
|
||||
|
@ -25,14 +25,15 @@ namespace Oqtane
|
||||
public class Startup
|
||||
{
|
||||
public IConfigurationRoot Configuration { get; }
|
||||
|
||||
private string _webRoot;
|
||||
|
||||
public Startup(IWebHostEnvironment env)
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
Configuration = builder.Build();
|
||||
|
||||
_webRoot = env.WebRootPath;
|
||||
AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(env.ContentRootPath, "Data"));
|
||||
}
|
||||
|
||||
@ -155,11 +156,7 @@ namespace Oqtane
|
||||
services.AddSingleton<DatabaseManager>();
|
||||
|
||||
// install any modules or themes ( this needs to occur BEFORE the assemblies are loaded into the app domain )
|
||||
#pragma warning disable ASP0000
|
||||
ServiceProvider sp = services.BuildServiceProvider();
|
||||
#pragma warning restore ASP0000
|
||||
var InstallationManager = sp.GetRequiredService<IInstallationManager>();
|
||||
InstallationManager.InstallPackages("Modules,Themes", false);
|
||||
InstallationManager.UnpackPackages("Modules,Themes", _webRoot);
|
||||
|
||||
// register transient scoped core services
|
||||
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();
|
||||
|
Reference in New Issue
Block a user