Storage: DI singleton
This commit is contained in:
parent
b34ba4b016
commit
4d440232f2
@ -2,17 +2,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ASC.Common.Utils;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ASC.Data.Storage.Configuration
|
||||
{
|
||||
public static class StorageConfigFactory
|
||||
{
|
||||
public static Storage Instance
|
||||
public static IServiceCollection AddStorage(this IServiceCollection services)
|
||||
{
|
||||
get
|
||||
{
|
||||
return ConfigurationManager.GetSetting<Storage>("Storage");
|
||||
}
|
||||
return services.AddSingleton(r => ConfigurationManager.GetSetting<Storage>("Storage"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,8 @@ using System.Threading.Tasks;
|
||||
using Amazon;
|
||||
using Amazon.S3;
|
||||
using Amazon.S3.Model;
|
||||
using ASC.Common.DependencyInjection;
|
||||
using ASC.Core;
|
||||
using ASC.Data.Storage.Configuration;
|
||||
|
||||
namespace ASC.Data.Storage.S3
|
||||
{
|
||||
@ -121,7 +121,7 @@ namespace ASC.Data.Storage.S3
|
||||
{
|
||||
if (!configured)
|
||||
{
|
||||
var config = StorageConfigFactory.Instance;
|
||||
var config = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||
var handler = config.GetHandler("s3");
|
||||
if (handler != null)
|
||||
{
|
||||
|
@ -26,8 +26,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using ASC.Common.Caching;
|
||||
@ -35,8 +33,6 @@ using ASC.Core;
|
||||
using ASC.Data.Storage.Configuration;
|
||||
using ASC.Core.Common.Configuration;
|
||||
using ASC.Data.Storage.DiscStorage;
|
||||
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using ASC.Common.DependencyInjection;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
@ -83,7 +79,7 @@ namespace ASC.Data.Storage
|
||||
var store = DataStoreCache.Get(tenant, module);
|
||||
if (store == null)
|
||||
{
|
||||
var section = StorageConfigFactory.Instance;
|
||||
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||
if (section == null)
|
||||
{
|
||||
throw new InvalidOperationException("config section not found");
|
||||
@ -103,7 +99,7 @@ namespace ASC.Data.Storage
|
||||
//Make tennant path
|
||||
tenant = TennantPath.CreatePath(tenant);
|
||||
|
||||
var section = StorageConfigFactory.Instance;
|
||||
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||
if (section == null)
|
||||
{
|
||||
throw new InvalidOperationException("config section not found");
|
||||
@ -116,7 +112,7 @@ namespace ASC.Data.Storage
|
||||
|
||||
public static IEnumerable<string> GetModuleList(string configpath, bool exceptDisabledMigration = false)
|
||||
{
|
||||
var section = StorageConfigFactory.Instance;
|
||||
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||
return section.Module
|
||||
.Where(x => x.Visible)
|
||||
.Where(x=> !exceptDisabledMigration || !x.DisableMigrate)
|
||||
@ -125,7 +121,7 @@ namespace ASC.Data.Storage
|
||||
|
||||
public static IEnumerable<string> GetDomainList(string configpath, string modulename)
|
||||
{
|
||||
var section = StorageConfigFactory.Instance;
|
||||
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||
if (section == null)
|
||||
{
|
||||
throw new ArgumentException("config section not found");
|
||||
@ -146,7 +142,7 @@ namespace ASC.Data.Storage
|
||||
// throw new InvalidOperationException("Application not hosted.");
|
||||
//}
|
||||
|
||||
var section = StorageConfigFactory.Instance;
|
||||
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||
if (section != null)
|
||||
{
|
||||
//old scheme
|
||||
@ -224,7 +220,7 @@ namespace ASC.Data.Storage
|
||||
|
||||
private static IDataStore GetDataStore(string tenant, string module, DataStoreConsumer consumer, IQuotaController controller)
|
||||
{
|
||||
var storage = StorageConfigFactory.Instance;
|
||||
var storage = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||
var moduleElement = storage.GetModuleElement(module);
|
||||
if (moduleElement == null)
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ namespace ASC.Data.Storage
|
||||
|
||||
static WebPath()
|
||||
{
|
||||
var section = StorageConfigFactory.Instance;
|
||||
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||
if (section != null)
|
||||
{
|
||||
Appenders = section.Appender;
|
||||
|
@ -22,6 +22,7 @@ using ASC.Core.Common;
|
||||
using ASC.Common;
|
||||
using ASC.Common.DependencyInjection;
|
||||
using ASC.Web.Core;
|
||||
using ASC.Data.Storage.Configuration;
|
||||
|
||||
namespace ASC.Web.Api
|
||||
{
|
||||
@ -65,8 +66,9 @@ namespace ASC.Web.Api
|
||||
builder.AddApplicationPart(a);
|
||||
}
|
||||
|
||||
services.AddLogManager(Configuration);
|
||||
services.AddWebItemManager();
|
||||
services.AddLogManager(Configuration)
|
||||
.AddStorage()
|
||||
.AddWebItemManager();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
|
@ -2,6 +2,7 @@ using ASC.Common.DependencyInjection;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Common.Utils;
|
||||
using ASC.Data.Storage;
|
||||
using ASC.Data.Storage.Configuration;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
|
||||
@ -40,6 +41,7 @@ namespace ASC.Web.Studio
|
||||
});
|
||||
|
||||
services.AddHttpContextAccessor()
|
||||
.AddStorage()
|
||||
.AddLogManager(Configuration);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user