mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-30 23:45:46 +02:00
New: Use native dotnet host and DryIoc
(cherry picked from commit d6170dbfedf27a6218afe242a0fae2eb8b368aec)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace NzbDrone.Core.Applications
|
||||
public ApplicationFactory(IApplicationStatusService applicationStatusService,
|
||||
IApplicationsRepository providerRepository,
|
||||
IEnumerable<IApplication> providers,
|
||||
IContainer container,
|
||||
IServiceProvider container,
|
||||
IEventAggregator eventAggregator,
|
||||
Logger logger)
|
||||
: base(providerRepository, providers, container, eventAggregator, logger)
|
||||
|
@@ -50,6 +50,8 @@ namespace NzbDrone.Core.Configuration
|
||||
public class ConfigFileProvider : IConfigFileProvider
|
||||
{
|
||||
public const string CONFIG_ELEMENT_NAME = "Config";
|
||||
public const int DEFAULT_PORT = 9696;
|
||||
public const int DEFAULT_SSL_PORT = 9898;
|
||||
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
@@ -135,9 +137,9 @@ namespace NzbDrone.Core.Configuration
|
||||
}
|
||||
}
|
||||
|
||||
public int Port => GetValueInt("Port", 9696);
|
||||
public int Port => GetValueInt("Port", DEFAULT_PORT);
|
||||
|
||||
public int SslPort => GetValueInt("SslPort", 9898);
|
||||
public int SslPort => GetValueInt("SslPort", DEFAULT_SSL_PORT);
|
||||
|
||||
public bool EnableSsl => GetValueBoolean("EnableSsl", false);
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Data.SQLite;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Exceptions;
|
||||
@@ -40,17 +39,6 @@ namespace NzbDrone.Core.Datastore
|
||||
Environment.SetEnvironmentVariable("No_SQLiteFunctions", "true");
|
||||
}
|
||||
|
||||
public static void RegisterDatabase(IContainer container)
|
||||
{
|
||||
var mainDb = new MainDatabase(container.Resolve<IDbFactory>().Create());
|
||||
|
||||
container.Register<IMainDatabase>(mainDb);
|
||||
|
||||
var logDb = new LogDatabase(container.Resolve<IDbFactory>().Create(MigrationType.Log));
|
||||
|
||||
container.Register<ILogDatabase>(logDb);
|
||||
}
|
||||
|
||||
public DbFactory(IMigrationController migrationController,
|
||||
IConnectionStringFactory connectionStringFactory,
|
||||
IDiskProvider diskProvider,
|
||||
|
@@ -0,0 +1,24 @@
|
||||
using DryIoc;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Extensions
|
||||
{
|
||||
public static class CompositionExtensions
|
||||
{
|
||||
public static IContainer AddDatabase(this IContainer container)
|
||||
{
|
||||
container.RegisterDelegate<IDbFactory, IMainDatabase>(f => new MainDatabase(f.Create()), Reuse.Singleton);
|
||||
container.RegisterDelegate<IDbFactory, ILogDatabase>(f => new LogDatabase(f.Create(MigrationType.Log)), Reuse.Singleton);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public static IContainer AddDummyDatabase(this IContainer container)
|
||||
{
|
||||
container.RegisterInstance<IMainDatabase>(new MainDatabase(null));
|
||||
container.RegisterInstance<ILogDatabase>(new LogDatabase(null));
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using FluentMigrator.Runner;
|
||||
@@ -7,6 +7,7 @@ using FluentMigrator.Runner.Processors;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||
{
|
||||
@@ -34,7 +35,7 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||
_logger.Info("*** Migrating {0} ***", connectionString);
|
||||
|
||||
var serviceProvider = new ServiceCollection()
|
||||
.AddLogging(lb => lb.AddProvider(_migrationLoggerProvider))
|
||||
.AddLogging(b => b.AddNLog())
|
||||
.AddFluentMigratorCore()
|
||||
.ConfigureRunner(
|
||||
builder => builder
|
||||
|
@@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using FluentMigrator.Runner;
|
||||
using FluentMigrator.Runner.Logging;
|
||||
using NLog;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||
{
|
||||
public class MigrationLogger : FluentMigratorLogger
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public MigrationLogger(Logger logger,
|
||||
FluentMigratorLoggerOptions options)
|
||||
: base(options)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected override void WriteHeading(string message)
|
||||
{
|
||||
_logger.Info("*** {0} ***", message);
|
||||
}
|
||||
|
||||
protected override void WriteSay(string message)
|
||||
{
|
||||
_logger.Debug(message);
|
||||
}
|
||||
|
||||
protected override void WriteEmphasize(string message)
|
||||
{
|
||||
_logger.Warn(message);
|
||||
}
|
||||
|
||||
protected override void WriteSql(string sql)
|
||||
{
|
||||
_logger.Debug(sql);
|
||||
}
|
||||
|
||||
protected override void WriteEmptySql()
|
||||
{
|
||||
_logger.Debug(@"No SQL statement executed.");
|
||||
}
|
||||
|
||||
protected override void WriteElapsedTime(TimeSpan timeSpan)
|
||||
{
|
||||
_logger.Debug("Took: {0}", timeSpan);
|
||||
}
|
||||
|
||||
protected override void WriteError(string message)
|
||||
{
|
||||
_logger.Error(message);
|
||||
}
|
||||
|
||||
protected override void WriteError(Exception exception)
|
||||
{
|
||||
_logger.Error(exception);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
using FluentMigrator.Runner;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||
{
|
||||
public class MigrationLoggerProvider : ILoggerProvider
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public MigrationLoggerProvider(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public ILogger CreateLogger(string categoryName)
|
||||
{
|
||||
return new MigrationLogger(_logger, new FluentMigratorLoggerOptions() { ShowElapsedTime = true, ShowSql = true });
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@@ -30,7 +30,7 @@ namespace NzbDrone.Core.Indexers
|
||||
IIndexerStatusService indexerStatusService,
|
||||
IIndexerRepository providerRepository,
|
||||
IEnumerable<IIndexer> providers,
|
||||
IContainer container,
|
||||
IServiceProvider container,
|
||||
IEventAggregator eventAggregator,
|
||||
Logger logger)
|
||||
: base(providerRepository, providers, container, eventAggregator, logger)
|
||||
|
@@ -5,6 +5,7 @@ using System.Net;
|
||||
using System.Threading;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
@@ -36,17 +37,18 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||
public class CommandQueueManager : IManageCommandQueue, IHandle<ApplicationStartedEvent>
|
||||
{
|
||||
private readonly ICommandRepository _repo;
|
||||
private readonly IServiceFactory _serviceFactory;
|
||||
private readonly KnownTypes _knownTypes;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private readonly CommandQueue _commandQueue;
|
||||
|
||||
public CommandQueueManager(ICommandRepository repo,
|
||||
IServiceFactory serviceFactory,
|
||||
KnownTypes knownTypes,
|
||||
Logger logger)
|
||||
{
|
||||
_repo = repo;
|
||||
_serviceFactory = serviceFactory;
|
||||
_knownTypes = knownTypes;
|
||||
_logger = logger;
|
||||
|
||||
_commandQueue = new CommandQueue();
|
||||
@@ -229,9 +231,8 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||
private dynamic GetCommand(string commandName)
|
||||
{
|
||||
commandName = commandName.Split('.').Last();
|
||||
|
||||
var commandType = _serviceFactory.GetImplementations(typeof(Command))
|
||||
.Single(c => c.Name.Equals(commandName, StringComparison.InvariantCultureIgnoreCase));
|
||||
var commands = _knownTypes.GetImplementations(typeof(Command));
|
||||
var commandType = commands.Single(c => c.Name.Equals(commandName, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
return Json.Deserialize("{}", commandType);
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
@@ -14,7 +15,7 @@ namespace NzbDrone.Core.Notifications
|
||||
|
||||
public class NotificationFactory : ProviderFactory<INotification, NotificationDefinition>, INotificationFactory
|
||||
{
|
||||
public NotificationFactory(INotificationRepository providerRepository, IEnumerable<INotification> providers, IContainer container, IEventAggregator eventAggregator, Logger logger)
|
||||
public NotificationFactory(INotificationRepository providerRepository, IEnumerable<INotification> providers, IServiceProvider container, IEventAggregator eventAggregator, Logger logger)
|
||||
: base(providerRepository, providers, container, eventAggregator, logger)
|
||||
{
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation.Results;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
@@ -15,7 +16,7 @@ namespace NzbDrone.Core.ThingiProvider
|
||||
where TProvider : IProvider
|
||||
{
|
||||
protected readonly IProviderRepository<TProviderDefinition> _providerRepository;
|
||||
private readonly IContainer _container;
|
||||
private readonly IServiceProvider _container;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly Logger _logger;
|
||||
|
||||
@@ -23,7 +24,7 @@ namespace NzbDrone.Core.ThingiProvider
|
||||
|
||||
protected ProviderFactory(IProviderRepository<TProviderDefinition> providerRepository,
|
||||
IEnumerable<TProvider> providers,
|
||||
IContainer container,
|
||||
IServiceProvider container,
|
||||
IEventAggregator eventAggregator,
|
||||
Logger logger)
|
||||
{
|
||||
@@ -123,7 +124,7 @@ namespace NzbDrone.Core.ThingiProvider
|
||||
public TProvider GetInstance(TProviderDefinition definition)
|
||||
{
|
||||
var type = GetImplementation(definition);
|
||||
var instance = (TProvider)_container.Resolve(type);
|
||||
var instance = (TProvider)_container.GetRequiredService(type);
|
||||
instance.Definition = definition;
|
||||
SetProviderCharacteristics(instance, definition);
|
||||
return instance;
|
||||
|
Reference in New Issue
Block a user