Browse Source

1) Separate interface IRunnable

2) ExternalSystem => IInitializable
pull/214/head
Sebastian Stehle 8 years ago
parent
commit
3b7c668cfc
  1. 4
      src/Squidex.Domain.Apps.Entities/Rules/RuleDequeuer.cs
  2. 4
      src/Squidex.Infrastructure.Azure/Assets/AzureBlobAssetStore.cs
  3. 4
      src/Squidex.Infrastructure.GetEventStore/EventSourcing/GetEventStore.cs
  4. 4
      src/Squidex.Infrastructure.GoogleCloud/Assets/GoogleCloudAssetStore.cs
  5. 4
      src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs
  6. 2
      src/Squidex.Infrastructure.MongoDb/States/MongoSnapshotStore.cs
  7. 4
      src/Squidex.Infrastructure.RabbitMq/CQRS/Events/RabbitMqEventConsumer.cs
  8. 4
      src/Squidex.Infrastructure.Redis/RedisPubSub.cs
  9. 4
      src/Squidex.Infrastructure/Assets/FolderAssetStore.cs
  10. 4
      src/Squidex.Infrastructure/EventSourcing/Grains/EventConsumerGrainManager.cs
  11. 15
      src/Squidex.Infrastructure/IInitializable.cs
  12. 6
      src/Squidex.Infrastructure/IRunnable.cs
  13. 4
      src/Squidex.Infrastructure/Log/FileChannel.cs
  14. 4
      src/Squidex.Infrastructure/States/StateFactory.cs
  15. 6
      src/Squidex/Config/Domain/AssetServices.cs
  16. 2
      src/Squidex/Config/Domain/EventPublishersServices.cs
  17. 4
      src/Squidex/Config/Domain/EventStoreServices.cs
  18. 2
      src/Squidex/Config/Domain/InfrastructureServices.cs
  19. 2
      src/Squidex/Config/Domain/PubSubServices.cs
  20. 6
      src/Squidex/Config/Domain/ReadServices.cs
  21. 30
      src/Squidex/Config/Domain/StoreServices.cs
  22. 16
      src/Squidex/Config/Domain/SystemExtensions.cs
  23. 3
      src/Squidex/WebStartup.cs
  24. 10
      tests/Squidex.Infrastructure.Tests/Assets/AssetStoreTests.cs
  25. 2
      tests/Squidex.Infrastructure.Tests/Assets/AzureBlobAssetStoreTests.cs
  26. 6
      tests/Squidex.Infrastructure.Tests/Assets/FolderAssetStoreTests.cs
  27. 2
      tests/Squidex.Infrastructure.Tests/Assets/GoogleCloudAssetStoreTests.cs
  28. 10
      tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerManagerTests.cs
  29. 2
      tests/Squidex.Infrastructure.Tests/States/StateEventSourcingTests.cs
  30. 2
      tests/Squidex.Infrastructure.Tests/States/StateSnapshotTests.cs

4
src/Squidex.Domain.Apps.Entities/Rules/RuleDequeuer.cs

@ -21,7 +21,7 @@ using Squidex.Infrastructure.Timers;
namespace Squidex.Domain.Apps.Entities.Rules namespace Squidex.Domain.Apps.Entities.Rules
{ {
public class RuleDequeuer : DisposableObjectBase, IExternalSystem public class RuleDequeuer : DisposableObjectBase, IRunnable
{ {
private readonly ActionBlock<IRuleEventEntity> requestBlock; private readonly ActionBlock<IRuleEventEntity> requestBlock;
private readonly IRuleEventRepository ruleEventRepository; private readonly IRuleEventRepository ruleEventRepository;
@ -63,7 +63,7 @@ namespace Squidex.Domain.Apps.Entities.Rules
} }
} }
public void Connect() public void Run()
{ {
} }

4
src/Squidex.Infrastructure.Azure/Assets/AzureBlobAssetStore.cs

@ -14,7 +14,7 @@ using Microsoft.WindowsAzure.Storage.Blob;
namespace Squidex.Infrastructure.Assets namespace Squidex.Infrastructure.Assets
{ {
public class AzureBlobAssetStore : IAssetStore, IExternalSystem public class AzureBlobAssetStore : IAssetStore, IInitializable
{ {
private const string AssetVersion = "AssetVersion"; private const string AssetVersion = "AssetVersion";
private const string AssetId = "AssetId"; private const string AssetId = "AssetId";
@ -31,7 +31,7 @@ namespace Squidex.Infrastructure.Assets
this.containerName = containerName; this.containerName = containerName;
} }
public void Connect() public void Initialize()
{ {
try try
{ {

4
src/Squidex.Infrastructure.GetEventStore/EventSourcing/GetEventStore.cs

@ -15,7 +15,7 @@ using EventStore.ClientAPI;
namespace Squidex.Infrastructure.EventSourcing namespace Squidex.Infrastructure.EventSourcing
{ {
public sealed class GetEventStore : IEventStore, IExternalSystem public sealed class GetEventStore : IEventStore, IInitializable
{ {
private const int WritePageSize = 500; private const int WritePageSize = 500;
private const int ReadPageSize = 500; private const int ReadPageSize = 500;
@ -37,7 +37,7 @@ namespace Squidex.Infrastructure.EventSourcing
{ {
} }
public void Connect() public void Initialize()
{ {
try try
{ {

4
src/Squidex.Infrastructure.GoogleCloud/Assets/GoogleCloudAssetStore.cs

@ -16,7 +16,7 @@ using Google.Cloud.Storage.V1;
namespace Squidex.Infrastructure.Assets namespace Squidex.Infrastructure.Assets
{ {
public sealed class GoogleCloudAssetStore : IAssetStore, IExternalSystem public sealed class GoogleCloudAssetStore : IAssetStore, IInitializable
{ {
private readonly string bucketName; private readonly string bucketName;
private StorageClient storageClient; private StorageClient storageClient;
@ -28,7 +28,7 @@ namespace Squidex.Infrastructure.Assets
this.bucketName = bucketName; this.bucketName = bucketName;
} }
public void Connect() public void Initialize()
{ {
try try
{ {

4
src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs

@ -17,7 +17,7 @@ using Squidex.Infrastructure.Tasks;
namespace Squidex.Infrastructure.MongoDb namespace Squidex.Infrastructure.MongoDb
{ {
public abstract class MongoRepositoryBase<TEntity> : IExternalSystem public abstract class MongoRepositoryBase<TEntity> : IInitializable
{ {
private const string CollectionFormat = "{0}Set"; private const string CollectionFormat = "{0}Set";
@ -106,7 +106,7 @@ namespace Squidex.Infrastructure.MongoDb
} }
} }
public void Connect() public void Initialize()
{ {
try try
{ {

2
src/Squidex.Infrastructure.MongoDb/States/MongoSnapshotStore.cs

@ -13,7 +13,7 @@ using Squidex.Infrastructure.MongoDb;
namespace Squidex.Infrastructure.States namespace Squidex.Infrastructure.States
{ {
public class MongoSnapshotStore<T, TKey> : MongoRepositoryBase<MongoState<T, TKey>>, ISnapshotStore<T, TKey>, IExternalSystem public class MongoSnapshotStore<T, TKey> : MongoRepositoryBase<MongoState<T, TKey>>, ISnapshotStore<T, TKey>, IInitializable
{ {
private readonly JsonSerializer serializer; private readonly JsonSerializer serializer;

4
src/Squidex.Infrastructure.RabbitMq/CQRS/Events/RabbitMqEventConsumer.cs

@ -15,7 +15,7 @@ using Squidex.Infrastructure.Tasks;
namespace Squidex.Infrastructure.EventSourcing namespace Squidex.Infrastructure.EventSourcing
{ {
public sealed class RabbitMqEventConsumer : DisposableObjectBase, IExternalSystem, IEventConsumer public sealed class RabbitMqEventConsumer : DisposableObjectBase, IInitializable, IEventConsumer
{ {
private readonly JsonSerializerSettings serializerSettings; private readonly JsonSerializerSettings serializerSettings;
private readonly string eventPublisherName; private readonly string eventPublisherName;
@ -61,7 +61,7 @@ namespace Squidex.Infrastructure.EventSourcing
} }
} }
public void Connect() public void Initialize()
{ {
try try
{ {

4
src/Squidex.Infrastructure.Redis/RedisPubSub.cs

@ -13,7 +13,7 @@ using StackExchange.Redis;
namespace Squidex.Infrastructure namespace Squidex.Infrastructure
{ {
public sealed class RedisPubSub : IPubSub, IExternalSystem public sealed class RedisPubSub : IPubSub, IInitializable
{ {
private readonly ConcurrentDictionary<string, object> subscriptions = new ConcurrentDictionary<string, object>(); private readonly ConcurrentDictionary<string, object> subscriptions = new ConcurrentDictionary<string, object>();
private readonly Lazy<IConnectionMultiplexer> redisClient; private readonly Lazy<IConnectionMultiplexer> redisClient;
@ -31,7 +31,7 @@ namespace Squidex.Infrastructure
redisSubscriber = new Lazy<ISubscriber>(() => redis.Value.GetSubscriber()); redisSubscriber = new Lazy<ISubscriber>(() => redis.Value.GetSubscriber());
} }
public void Connect() public void Initialize()
{ {
try try
{ {

4
src/Squidex.Infrastructure/Assets/FolderAssetStore.cs

@ -14,7 +14,7 @@ using Squidex.Infrastructure.Tasks;
namespace Squidex.Infrastructure.Assets namespace Squidex.Infrastructure.Assets
{ {
public sealed class FolderAssetStore : IAssetStore, IExternalSystem public sealed class FolderAssetStore : IAssetStore, IInitializable
{ {
private readonly ISemanticLog log; private readonly ISemanticLog log;
private readonly DirectoryInfo directory; private readonly DirectoryInfo directory;
@ -29,7 +29,7 @@ namespace Squidex.Infrastructure.Assets
directory = new DirectoryInfo(path); directory = new DirectoryInfo(path);
} }
public void Connect() public void Initialize()
{ {
try try
{ {

4
src/Squidex.Infrastructure/EventSourcing/Grains/EventConsumerGrainManager.cs

@ -15,7 +15,7 @@ using Squidex.Infrastructure.States;
namespace Squidex.Infrastructure.EventSourcing.Grains namespace Squidex.Infrastructure.EventSourcing.Grains
{ {
public sealed class EventConsumerGrainManager : DisposableObjectBase, IExternalSystem public sealed class EventConsumerGrainManager : DisposableObjectBase, IRunnable
{ {
private readonly IStateFactory factory; private readonly IStateFactory factory;
private readonly IPubSub pubSub; private readonly IPubSub pubSub;
@ -33,7 +33,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
this.consumers = consumers.ToList(); this.consumers = consumers.ToList();
} }
public void Connect() public void Run()
{ {
var actors = new Dictionary<string, EventConsumerGrain>(); var actors = new Dictionary<string, EventConsumerGrain>();

15
src/Squidex.Infrastructure/IInitializable.cs

@ -0,0 +1,15 @@
// ==========================================================================
// IInitializable.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
namespace Squidex.Infrastructure
{
public interface IInitializable
{
void Initialize();
}
}

6
src/Squidex.Infrastructure/IExternalSystem.cs → src/Squidex.Infrastructure/IRunnable.cs

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// IExternalSystem.cs // IRunnable.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
@ -8,8 +8,8 @@
namespace Squidex.Infrastructure namespace Squidex.Infrastructure
{ {
public interface IExternalSystem public interface IRunnable
{ {
void Connect(); void Run();
} }
} }

4
src/Squidex.Infrastructure/Log/FileChannel.cs

@ -10,7 +10,7 @@ using Squidex.Infrastructure.Log.Internal;
namespace Squidex.Infrastructure.Log namespace Squidex.Infrastructure.Log
{ {
public sealed class FileChannel : DisposableObjectBase, ILogChannel, IExternalSystem public sealed class FileChannel : DisposableObjectBase, ILogChannel, IInitializable
{ {
private readonly FileLogProcessor processor; private readonly FileLogProcessor processor;
@ -34,7 +34,7 @@ namespace Squidex.Infrastructure.Log
processor.EnqueueMessage(new LogMessageEntry { Message = message }); processor.EnqueueMessage(new LogMessageEntry { Message = message });
} }
public void Connect() public void Initialize()
{ {
processor.Connect(); processor.Connect();
} }

4
src/Squidex.Infrastructure/States/StateFactory.cs

@ -15,7 +15,7 @@ using Squidex.Infrastructure.EventSourcing;
namespace Squidex.Infrastructure.States namespace Squidex.Infrastructure.States
{ {
public sealed class StateFactory : DisposableObjectBase, IExternalSystem, IStateFactory public sealed class StateFactory : DisposableObjectBase, IInitializable, IStateFactory
{ {
private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(10); private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(10);
private readonly IPubSub pubSub; private readonly IPubSub pubSub;
@ -70,7 +70,7 @@ namespace Squidex.Infrastructure.States
this.streamNameResolver = streamNameResolver; this.streamNameResolver = streamNameResolver;
} }
public void Connect() public void Initialize()
{ {
pubSubSubscription = pubSub.Subscribe<InvalidateMessage>(m => pubSubSubscription = pubSub.Subscribe<InvalidateMessage>(m =>
{ {

6
src/Squidex/Config/Domain/AssetServices.cs

@ -26,7 +26,7 @@ namespace Squidex.Config.Domain
services.AddSingletonAs(c => new FolderAssetStore(path, c.GetRequiredService<ISemanticLog>())) services.AddSingletonAs(c => new FolderAssetStore(path, c.GetRequiredService<ISemanticLog>()))
.As<IAssetStore>() .As<IAssetStore>()
.As<IExternalSystem>(); .As<IInitializable>();
}, },
["GoogleCloud"] = () => ["GoogleCloud"] = () =>
{ {
@ -34,7 +34,7 @@ namespace Squidex.Config.Domain
services.AddSingletonAs(c => new GoogleCloudAssetStore(bucketName)) services.AddSingletonAs(c => new GoogleCloudAssetStore(bucketName))
.As<IAssetStore>() .As<IAssetStore>()
.As<IExternalSystem>(); .As<IInitializable>();
}, },
["AzureBlob"] = () => ["AzureBlob"] = () =>
{ {
@ -43,7 +43,7 @@ namespace Squidex.Config.Domain
services.AddSingletonAs(c => new AzureBlobAssetStore(connectionString, containerName)) services.AddSingletonAs(c => new AzureBlobAssetStore(connectionString, containerName))
.As<IAssetStore>() .As<IAssetStore>()
.As<IExternalSystem>(); .As<IInitializable>();
} }
}); });
} }

2
src/Squidex/Config/Domain/EventPublishersServices.cs

@ -56,7 +56,7 @@ namespace Squidex.Config.Domain
{ {
services.AddSingletonAs(c => new RabbitMqEventConsumer(c.GetRequiredService<JsonSerializerSettings>(), name, publisherConfig, exchange, eventsFilter)) services.AddSingletonAs(c => new RabbitMqEventConsumer(c.GetRequiredService<JsonSerializerSettings>(), name, publisherConfig, exchange, eventsFilter))
.As<IEventConsumer>() .As<IEventConsumer>()
.As<IExternalSystem>(); .As<IInitializable>();
} }
} }
else else

4
src/Squidex/Config/Domain/EventStoreServices.cs

@ -33,7 +33,7 @@ namespace Squidex.Config.Domain
return new MongoEventStore(mongDatabase, c.GetRequiredService<IEventNotifier>()); return new MongoEventStore(mongDatabase, c.GetRequiredService<IEventNotifier>());
}) })
.As<IExternalSystem>() .As<IInitializable>()
.As<IEventStore>(); .As<IEventStore>();
}, },
["GetEventStore"] = () => ["GetEventStore"] = () =>
@ -45,7 +45,7 @@ namespace Squidex.Config.Domain
var connection = EventStoreConnection.Create(eventStoreConfiguration); var connection = EventStoreConnection.Create(eventStoreConfiguration);
services.AddSingletonAs(c => new GetEventStore(connection, eventStorePrefix, eventStoreProjectionHost)) services.AddSingletonAs(c => new GetEventStore(connection, eventStorePrefix, eventStoreProjectionHost))
.As<IExternalSystem>() .As<IInitializable>()
.As<IEventStore>(); .As<IEventStore>();
} }
}); });

2
src/Squidex/Config/Domain/InfrastructureServices.cs

@ -45,7 +45,7 @@ namespace Squidex.Config.Domain
{ {
services.AddSingletonAs(new FileChannel(loggingFile)) services.AddSingletonAs(new FileChannel(loggingFile))
.As<ILogChannel>() .As<ILogChannel>()
.As<IExternalSystem>(); .As<IInitializable>();
} }
services.AddSingletonAs(c => new ApplicationInfoLogAppender(typeof(Program).Assembly, Guid.NewGuid())) services.AddSingletonAs(c => new ApplicationInfoLogAppender(typeof(Program).Assembly, Guid.NewGuid()))

2
src/Squidex/Config/Domain/PubSubServices.cs

@ -33,7 +33,7 @@ namespace Squidex.Config.Domain
services.AddSingletonAs(c => new RedisPubSub(redis, c.GetRequiredService<ISemanticLog>())) services.AddSingletonAs(c => new RedisPubSub(redis, c.GetRequiredService<ISemanticLog>()))
.As<IPubSub>() .As<IPubSub>()
.As<IExternalSystem>(); .As<IInitializable>();
} }
}); });
} }

6
src/Squidex/Config/Domain/ReadServices.cs

@ -44,9 +44,9 @@ namespace Squidex.Config.Domain
services.AddTransient<EventConsumerGrain>(); services.AddTransient<EventConsumerGrain>();
services.AddSingletonAs<EventConsumerGrainManager>() services.AddSingletonAs<EventConsumerGrainManager>()
.As<IExternalSystem>(); .As<IRunnable>();
services.AddSingletonAs<RuleDequeuer>() services.AddSingletonAs<RuleDequeuer>()
.As<IExternalSystem>(); .As<IRunnable>();
} }
var exposeSourceUrl = config.GetOptionalValue("assetStore:exposeSourceUrl", true); var exposeSourceUrl = config.GetOptionalValue("assetStore:exposeSourceUrl", true);
@ -58,7 +58,7 @@ namespace Squidex.Config.Domain
.As<IGraphQLUrlGenerator>(); .As<IGraphQLUrlGenerator>();
services.AddSingletonAs<StateFactory>() services.AddSingletonAs<StateFactory>()
.As<IExternalSystem>() .As<IInitializable>()
.As<IStateFactory>(); .As<IStateFactory>();
services.AddSingletonAs(c => c.GetService<IOptions<MyUsageOptions>>()?.Value?.Plans.OrEmpty()); services.AddSingletonAs(c => c.GetService<IOptions<MyUsageOptions>>()?.Value?.Plans.OrEmpty());

30
src/Squidex/Config/Domain/StoreServices.cs

@ -64,74 +64,74 @@ namespace Squidex.Config.Domain
services.AddSingletonAs(c => new MongoXmlRepository(mongoDatabase)) services.AddSingletonAs(c => new MongoXmlRepository(mongoDatabase))
.As<IXmlRepository>() .As<IXmlRepository>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoMigrationStatus(mongoDatabase)) services.AddSingletonAs(c => new MongoMigrationStatus(mongoDatabase))
.As<IMigrationStatus>() .As<IMigrationStatus>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoSnapshotStore<EventConsumerState, string>(mongoDatabase, c.GetRequiredService<JsonSerializer>())) services.AddSingletonAs(c => new MongoSnapshotStore<EventConsumerState, string>(mongoDatabase, c.GetRequiredService<JsonSerializer>()))
.As<ISnapshotStore<EventConsumerState, string>>() .As<ISnapshotStore<EventConsumerState, string>>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoUserStore(mongoDatabase)) services.AddSingletonAs(c => new MongoUserStore(mongoDatabase))
.As<IUserStore<IUser>>() .As<IUserStore<IUser>>()
.As<IUserFactory>() .As<IUserFactory>()
.As<IUserResolver>() .As<IUserResolver>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoRoleStore(mongoDatabase)) services.AddSingletonAs(c => new MongoRoleStore(mongoDatabase))
.As<IRoleStore<IRole>>() .As<IRoleStore<IRole>>()
.As<IRoleFactory>() .As<IRoleFactory>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoPersistedGrantStore(mongoDatabase)) services.AddSingletonAs(c => new MongoPersistedGrantStore(mongoDatabase))
.As<IPersistedGrantStore>() .As<IPersistedGrantStore>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoUsageStore(mongoDatabase)) services.AddSingletonAs(c => new MongoUsageStore(mongoDatabase))
.As<IUsageStore>() .As<IUsageStore>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoRuleEventRepository(mongoDatabase)) services.AddSingletonAs(c => new MongoRuleEventRepository(mongoDatabase))
.As<IRuleEventRepository>() .As<IRuleEventRepository>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoAppRepository(mongoDatabase)) services.AddSingletonAs(c => new MongoAppRepository(mongoDatabase))
.As<IAppRepository>() .As<IAppRepository>()
.As<ISnapshotStore<AppState, Guid>>() .As<ISnapshotStore<AppState, Guid>>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoAssetRepository(mongoDatabase)) services.AddSingletonAs(c => new MongoAssetRepository(mongoDatabase))
.As<IAssetRepository>() .As<IAssetRepository>()
.As<ISnapshotStore<AssetState, Guid>>() .As<ISnapshotStore<AssetState, Guid>>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoRuleRepository(mongoDatabase)) services.AddSingletonAs(c => new MongoRuleRepository(mongoDatabase))
.As<IRuleRepository>() .As<IRuleRepository>()
.As<ISnapshotStore<RuleState, Guid>>() .As<ISnapshotStore<RuleState, Guid>>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoSchemaRepository(mongoDatabase)) services.AddSingletonAs(c => new MongoSchemaRepository(mongoDatabase))
.As<ISchemaRepository>() .As<ISchemaRepository>()
.As<ISnapshotStore<SchemaState, Guid>>() .As<ISnapshotStore<SchemaState, Guid>>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoContentRepository(mongoContentDatabase, c.GetService<IAppProvider>())) services.AddSingletonAs(c => new MongoContentRepository(mongoContentDatabase, c.GetService<IAppProvider>()))
.As<IContentRepository>() .As<IContentRepository>()
.As<ISnapshotStore<ContentState, Guid>>() .As<ISnapshotStore<ContentState, Guid>>()
.As<IEventConsumer>() .As<IEventConsumer>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoHistoryEventRepository(mongoDatabase, c.GetServices<IHistoryEventsCreator>())) services.AddSingletonAs(c => new MongoHistoryEventRepository(mongoDatabase, c.GetServices<IHistoryEventsCreator>()))
.As<IHistoryEventRepository>() .As<IHistoryEventRepository>()
.As<IEventConsumer>() .As<IEventConsumer>()
.As<IExternalSystem>(); .As<IInitializable>();
services.AddSingletonAs(c => new MongoAssetStatsRepository(mongoDatabase)) services.AddSingletonAs(c => new MongoAssetStatsRepository(mongoDatabase))
.As<IAssetStatsRepository>() .As<IAssetStatsRepository>()
.As<IEventConsumer>() .As<IEventConsumer>()
.As<IExternalSystem>(); .As<IInitializable>();
} }
}); });
} }

16
src/Squidex/Config/Domain/SystemExtensions.cs

@ -16,13 +16,23 @@ namespace Squidex.Config.Domain
{ {
public static class SystemExtensions public static class SystemExtensions
{ {
public static void TestExternalSystems(this IServiceProvider services) public static void InitializeAll(this IServiceProvider services)
{ {
var systems = services.GetRequiredService<IEnumerable<IExternalSystem>>(); var systems = services.GetRequiredService<IEnumerable<IInitializable>>();
foreach (var system in systems) foreach (var system in systems)
{ {
system.Connect(); system.Initialize();
}
}
public static void RunAll(this IServiceProvider services)
{
var systems = services.GetRequiredService<IEnumerable<IRunnable>>();
foreach (var system in systems)
{
system.Run();
} }
} }

3
src/Squidex/WebStartup.cs

@ -39,8 +39,9 @@ namespace Squidex
public void Configure(IApplicationBuilder app) public void Configure(IApplicationBuilder app)
{ {
app.ApplicationServices.LogConfiguration(); app.ApplicationServices.LogConfiguration();
app.ApplicationServices.InitializeAll();
app.ApplicationServices.Migrate(); app.ApplicationServices.Migrate();
app.ApplicationServices.TestExternalSystems(); app.ApplicationServices.RunAll();
app.UseMyCors(); app.UseMyCors();
app.UseMyForwardingRules(); app.UseMyForwardingRules();

10
tests/Squidex.Infrastructure.Tests/Assets/AssetStoreTests.cs

@ -34,7 +34,7 @@ namespace Squidex.Infrastructure.Assets
[Fact] [Fact]
public Task Should_throw_exception_if_asset_to_download_is_not_found() public Task Should_throw_exception_if_asset_to_download_is_not_found()
{ {
((IExternalSystem)Sut).Connect(); ((IInitializable)Sut).Initialize();
return Assert.ThrowsAsync<AssetNotFoundException>(() => Sut.DownloadAsync(Id(), 1, "suffix", new MemoryStream())); return Assert.ThrowsAsync<AssetNotFoundException>(() => Sut.DownloadAsync(Id(), 1, "suffix", new MemoryStream()));
} }
@ -42,7 +42,7 @@ namespace Squidex.Infrastructure.Assets
[Fact] [Fact]
public Task Should_throw_exception_if_asset_to_copy_is_not_found() public Task Should_throw_exception_if_asset_to_copy_is_not_found()
{ {
((IExternalSystem)Sut).Connect(); ((IInitializable)Sut).Initialize();
return Assert.ThrowsAsync<AssetNotFoundException>(() => Sut.CopyTemporaryAsync(Id(), Id(), 1, null)); return Assert.ThrowsAsync<AssetNotFoundException>(() => Sut.CopyTemporaryAsync(Id(), Id(), 1, null));
} }
@ -50,7 +50,7 @@ namespace Squidex.Infrastructure.Assets
[Fact] [Fact]
public async Task Should_read_and_write_file() public async Task Should_read_and_write_file()
{ {
((IExternalSystem)Sut).Connect(); ((IInitializable)Sut).Initialize();
var assetId = Id(); var assetId = Id();
var assetData = new MemoryStream(new byte[] { 0x1, 0x2, 0x3, 0x4 }); var assetData = new MemoryStream(new byte[] { 0x1, 0x2, 0x3, 0x4 });
@ -67,7 +67,7 @@ namespace Squidex.Infrastructure.Assets
[Fact] [Fact]
public async Task Should_commit_temporary_file() public async Task Should_commit_temporary_file()
{ {
((IExternalSystem)Sut).Connect(); ((IInitializable)Sut).Initialize();
var tempId = Id(); var tempId = Id();
@ -87,7 +87,7 @@ namespace Squidex.Infrastructure.Assets
[Fact] [Fact]
public async Task Should_ignore_when_deleting_twice() public async Task Should_ignore_when_deleting_twice()
{ {
((IExternalSystem)Sut).Connect(); ((IInitializable)Sut).Initialize();
var tempId = Id(); var tempId = Id();

2
tests/Squidex.Infrastructure.Tests/Assets/AzureBlobAssetStoreTests.cs

@ -25,7 +25,7 @@ namespace Squidex.Infrastructure.Assets
// [Fact] // [Fact]
public void Should_calculate_source_url() public void Should_calculate_source_url()
{ {
Sut.Connect(); Sut.Initialize();
var id = Guid.NewGuid().ToString(); var id = Guid.NewGuid().ToString();

6
tests/Squidex.Infrastructure.Tests/Assets/FolderAssetStoreTests.cs

@ -34,13 +34,13 @@ namespace Squidex.Infrastructure.Assets
[Fact] [Fact]
public void Should_throw_when_creating_directory_failed() public void Should_throw_when_creating_directory_failed()
{ {
Assert.Throws<ConfigurationException>(() => new FolderAssetStore(CreateInvalidPath(), A.Dummy<ISemanticLog>()).Connect()); Assert.Throws<ConfigurationException>(() => new FolderAssetStore(CreateInvalidPath(), A.Dummy<ISemanticLog>()).Initialize());
} }
[Fact] [Fact]
public void Should_create_directory_when_connecting() public void Should_create_directory_when_connecting()
{ {
Sut.Connect(); Sut.Initialize();
Assert.True(Directory.Exists(testFolder)); Assert.True(Directory.Exists(testFolder));
} }
@ -48,7 +48,7 @@ namespace Squidex.Infrastructure.Assets
[Fact] [Fact]
public void Should_calculate_source_url() public void Should_calculate_source_url()
{ {
Sut.Connect(); Sut.Initialize();
var id = Guid.NewGuid().ToString(); var id = Guid.NewGuid().ToString();

2
tests/Squidex.Infrastructure.Tests/Assets/GoogleCloudAssetStoreTests.cs

@ -25,7 +25,7 @@ namespace Squidex.Infrastructure.Assets
// [Fact] // [Fact]
public void Should_calculate_source_url() public void Should_calculate_source_url()
{ {
Sut.Connect(); Sut.Initialize();
var id = Guid.NewGuid().ToString(); var id = Guid.NewGuid().ToString();

10
tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerManagerTests.cs

@ -42,7 +42,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
[Fact] [Fact]
public void Should_activate_all_actors() public void Should_activate_all_actors()
{ {
sut.Connect(); sut.Run();
A.CallTo(() => actor1.Activate(consumer1)) A.CallTo(() => actor1.Activate(consumer1))
.MustHaveHappened(); .MustHaveHappened();
@ -54,7 +54,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
[Fact] [Fact]
public void Should_start_correct_actor() public void Should_start_correct_actor()
{ {
sut.Connect(); sut.Run();
pubSub.Publish(new StartConsumerMessage { ConsumerName = consumerName1 }, true); pubSub.Publish(new StartConsumerMessage { ConsumerName = consumerName1 }, true);
@ -68,7 +68,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
[Fact] [Fact]
public void Should_stop_correct_actor() public void Should_stop_correct_actor()
{ {
sut.Connect(); sut.Run();
pubSub.Publish(new StopConsumerMessage { ConsumerName = consumerName1 }, true); pubSub.Publish(new StopConsumerMessage { ConsumerName = consumerName1 }, true);
@ -82,7 +82,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
[Fact] [Fact]
public void Should_reset_correct_actor() public void Should_reset_correct_actor()
{ {
sut.Connect(); sut.Run();
pubSub.Publish(new ResetConsumerMessage { ConsumerName = consumerName2 }, true); pubSub.Publish(new ResetConsumerMessage { ConsumerName = consumerName2 }, true);
@ -96,7 +96,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
[Fact] [Fact]
public async Task Should_get_state_from_all_actors() public async Task Should_get_state_from_all_actors()
{ {
sut.Connect(); sut.Run();
A.CallTo(() => actor1.GetState()) A.CallTo(() => actor1.GetState())
.Returns(new EventConsumerInfo { Name = consumerName1, Position = "123 " }); .Returns(new EventConsumerInfo { Name = consumerName1, Position = "123 " });

2
tests/Squidex.Infrastructure.Tests/States/StateEventSourcingTests.cs

@ -88,7 +88,7 @@ namespace Squidex.Infrastructure.States
.Returns(key); .Returns(key);
sut = new StateFactory(pubSub, cache, eventStore, eventDataFormatter, services, streamNameResolver); sut = new StateFactory(pubSub, cache, eventStore, eventDataFormatter, services, streamNameResolver);
sut.Connect(); sut.Initialize();
} }
[Fact] [Fact]

2
tests/Squidex.Infrastructure.Tests/States/StateSnapshotTests.cs

@ -75,7 +75,7 @@ namespace Squidex.Infrastructure.States
.Returns(snapshotStore); .Returns(snapshotStore);
sut = new StateFactory(pubSub, cache, eventStore, eventDataFormatter, services, streamNameResolver); sut = new StateFactory(pubSub, cache, eventStore, eventDataFormatter, services, streamNameResolver);
sut.Connect(); sut.Initialize();
} }
public void Dispose() public void Dispose()

Loading…
Cancel
Save