mirror of https://github.com/Squidex/squidex.git
20 changed files with 475 additions and 138 deletions
@ -0,0 +1,78 @@ |
|||
// ==========================================================================
|
|||
// EventStoreModule.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Autofac; |
|||
using Microsoft.Extensions.Configuration; |
|||
using RabbitMQ.Client; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.RabbitMq; |
|||
|
|||
namespace Squidex.Config.Domain |
|||
{ |
|||
public class EventBusModule : Module |
|||
{ |
|||
public IConfiguration Configuration { get; } |
|||
|
|||
public EventBusModule(IConfiguration configuration) |
|||
{ |
|||
Configuration = configuration; |
|||
} |
|||
|
|||
protected override void Load(ContainerBuilder builder) |
|||
{ |
|||
var storeType = Configuration.GetValue<string>("squidex:eventBus:type"); |
|||
|
|||
if (string.IsNullOrWhiteSpace(storeType)) |
|||
{ |
|||
throw new ConfigurationException("You must specify the event bus type in the 'squidex:eventBus:type' configuration section."); |
|||
} |
|||
|
|||
var canCatch = Configuration.GetValue<bool>("squidex:eventBus:catch"); |
|||
|
|||
builder.RegisterType<EventReceiver>() |
|||
.WithParameter(new NamedParameter("canCatch", canCatch)) |
|||
.AsSelf() |
|||
.SingleInstance(); |
|||
|
|||
if (string.Equals(storeType, "Memory", StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
builder.RegisterType<InMemoryEventBus>() |
|||
.As<IEventStream>() |
|||
.As<IEventPublisher>() |
|||
.SingleInstance(); |
|||
} |
|||
if (string.Equals(storeType, "RabbitMq", StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
var connectionString = Configuration.GetValue<string>("squidex:eventBus:rabbitMq:connectionString"); |
|||
|
|||
if (string.IsNullOrWhiteSpace(connectionString) || !Uri.IsWellFormedUriString(connectionString, UriKind.Absolute)) |
|||
{ |
|||
throw new ConfigurationException("You must specify the RabbitMq connection string in the 'squidex:eventBus:rabbitMq:connectionString' configuration section."); |
|||
} |
|||
|
|||
builder.Register(c => |
|||
{ |
|||
var connectionFactory = new ConnectionFactory(); |
|||
|
|||
connectionFactory.SetUri(new Uri(connectionString)); |
|||
|
|||
return new RabbitMqEventBus(connectionFactory, canCatch); |
|||
}) |
|||
.As<IEventStream>() |
|||
.As<IEventPublisher>() |
|||
.SingleInstance(); |
|||
} |
|||
else |
|||
{ |
|||
throw new ConfigurationException($"Unsupported store type '{storeType}' for key 'squidex:eventStore:type', supported: Memory, RabbmitMq."); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
// ==========================================================================
|
|||
// EventStoreModule.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Autofac; |
|||
using Microsoft.Extensions.Configuration; |
|||
using MongoDB.Driver; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.MongoDb.EventStore; |
|||
|
|||
namespace Squidex.Config.Domain |
|||
{ |
|||
public class EventStoreModule : Module |
|||
{ |
|||
public IConfiguration Configuration { get; } |
|||
|
|||
public EventStoreModule(IConfiguration configuration) |
|||
{ |
|||
Configuration = configuration; |
|||
} |
|||
|
|||
protected override void Load(ContainerBuilder builder) |
|||
{ |
|||
var storeType = Configuration.GetValue<string>("squidex:eventStore:type"); |
|||
|
|||
if (string.IsNullOrWhiteSpace(storeType)) |
|||
{ |
|||
throw new ConfigurationException("You must specify the store type in the 'squidex:eventStore:type' configuration section."); |
|||
} |
|||
|
|||
if (string.Equals(storeType, "MongoDb", StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
var databaseName = Configuration.GetValue<string>("squidex:eventStore:mongoDb:databaseName"); |
|||
|
|||
if (string.IsNullOrWhiteSpace(databaseName)) |
|||
{ |
|||
throw new ConfigurationException("You must specify the MongoDB database name in the 'squidex:eventStore:mongoDb:databaseName' configuration section."); |
|||
} |
|||
|
|||
var connectionString = Configuration.GetValue<string>("squidex:eventStore:mongoDb:connectionString"); |
|||
|
|||
if (string.IsNullOrWhiteSpace(connectionString)) |
|||
{ |
|||
throw new ConfigurationException("You must specify the MongoDB connection string in the 'squidex:eventStore:mongoDb:connectionString' configuration section."); |
|||
} |
|||
|
|||
builder.Register(context => |
|||
{ |
|||
var mongoDbClient = new MongoClient(connectionString); |
|||
var mongoDatabase = mongoDbClient.GetDatabase(databaseName); |
|||
|
|||
var eventStore = new MongoEventStore(mongoDatabase); |
|||
|
|||
return eventStore; |
|||
}) |
|||
.As<IExternalSystem>() |
|||
.As<IEventStore>() |
|||
.SingleInstance(); |
|||
} |
|||
else |
|||
{ |
|||
throw new ConfigurationException($"Unsupported store type '{storeType}' for key 'squidex:eventStore:type', supported: MongoDb."); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
// ==========================================================================
|
|||
// StoreModule.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Autofac; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Config.Domain |
|||
{ |
|||
public class StoreModule : Module |
|||
{ |
|||
public IConfiguration Configuration { get; } |
|||
|
|||
public StoreModule(IConfiguration configuration) |
|||
{ |
|||
Configuration = configuration; |
|||
} |
|||
|
|||
protected override void Load(ContainerBuilder builder) |
|||
{ |
|||
var storeType = Configuration.GetValue<string>("squidex:stores:type"); |
|||
|
|||
if (string.IsNullOrWhiteSpace(storeType)) |
|||
{ |
|||
throw new ConfigurationException("You must specify the store type in the 'squidex:stores:type' configuration section."); |
|||
} |
|||
|
|||
if (string.Equals(storeType, "MongoDB", StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
builder.RegisterModule(new StoreMongoDbModule(Configuration)); |
|||
} |
|||
else |
|||
{ |
|||
throw new ConfigurationException($"Unsupported store type '{storeType}' for key 'squidex:stores:type', supported: MongoDb."); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,131 @@ |
|||
// ==========================================================================
|
|||
// StoreMongoDbModule.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Autofac; |
|||
using Autofac.Core; |
|||
using IdentityServer4.Stores; |
|||
using Microsoft.AspNetCore.Identity; |
|||
using Microsoft.AspNetCore.Identity.MongoDB; |
|||
using Microsoft.Extensions.Configuration; |
|||
using MongoDB.Driver; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.CQRS.Replay; |
|||
using Squidex.Read.Apps.Repositories; |
|||
using Squidex.Read.Contents.Repositories; |
|||
using Squidex.Read.History.Repositories; |
|||
using Squidex.Read.MongoDb; |
|||
using Squidex.Read.MongoDb.Apps; |
|||
using Squidex.Read.MongoDb.Contents; |
|||
using Squidex.Read.MongoDb.History; |
|||
using Squidex.Read.MongoDb.Infrastructure; |
|||
using Squidex.Read.MongoDb.Schemas; |
|||
using Squidex.Read.MongoDb.Users; |
|||
using Squidex.Read.Schemas.Repositories; |
|||
using Squidex.Read.Users.Repositories; |
|||
|
|||
namespace Squidex.Config.Domain |
|||
{ |
|||
public class StoreMongoDbModule : Module |
|||
{ |
|||
private const string MongoDatabaseName = "string"; |
|||
|
|||
public IConfiguration Configuration { get; } |
|||
|
|||
public StoreMongoDbModule(IConfiguration configuration) |
|||
{ |
|||
Configuration = configuration; |
|||
} |
|||
|
|||
protected override void Load(ContainerBuilder builder) |
|||
{ |
|||
var databaseName = Configuration.GetValue<string>("squidex:stores:mongoDb:databaseName"); |
|||
|
|||
if (string.IsNullOrWhiteSpace(databaseName)) |
|||
{ |
|||
throw new ConfigurationException("You must specify the MongoDB database name in the 'squidex:stores:mongoDb:databaseName' configuration section."); |
|||
} |
|||
|
|||
var connectionString = Configuration.GetValue<string>("squidex:stores:mongoDb:connectionString"); |
|||
|
|||
if (string.IsNullOrWhiteSpace(connectionString)) |
|||
{ |
|||
throw new ConfigurationException("You must specify the MongoDB connection string in the 'squidex:stores:mongoDb:connectionString' configuration section."); |
|||
} |
|||
|
|||
builder.Register(context => |
|||
{ |
|||
var mongoDbClient = new MongoClient(connectionString); |
|||
var mongoDatabase = mongoDbClient.GetDatabase(databaseName); |
|||
|
|||
return mongoDatabase; |
|||
}).Named<IMongoDatabase>(MongoDatabaseName).SingleInstance(); |
|||
|
|||
builder.Register<IUserStore<IdentityUser>>(context => |
|||
{ |
|||
var usersCollection = context.ResolveNamed<IMongoDatabase>(MongoDatabaseName).GetCollection<IdentityUser>("Identity_Users"); |
|||
|
|||
IndexChecks.EnsureUniqueIndexOnNormalizedEmail(usersCollection); |
|||
IndexChecks.EnsureUniqueIndexOnNormalizedUserName(usersCollection); |
|||
|
|||
return new UserStore<IdentityUser>(usersCollection); |
|||
}).SingleInstance(); |
|||
|
|||
builder.Register<IRoleStore<IdentityRole>>(context => |
|||
{ |
|||
var rolesCollection = context.ResolveNamed<IMongoDatabase>(MongoDatabaseName).GetCollection<IdentityRole>("Identity_Roles"); |
|||
|
|||
IndexChecks.EnsureUniqueIndexOnNormalizedRoleName(rolesCollection); |
|||
|
|||
return new RoleStore<IdentityRole>(rolesCollection); |
|||
}).SingleInstance(); |
|||
|
|||
builder.RegisterType<MongoUserRepository>() |
|||
.As<IUserRepository>() |
|||
.InstancePerLifetimeScope(); |
|||
|
|||
builder.RegisterType<MongoDbStoresExternalSystem>() |
|||
.WithParameter(ResolvedParameter.ForNamed<IMongoDatabase>(MongoDatabaseName)) |
|||
.As<IExternalSystem>() |
|||
.InstancePerLifetimeScope(); |
|||
|
|||
builder.RegisterType<MongoPersistedGrantStore>() |
|||
.WithParameter(ResolvedParameter.ForNamed<IMongoDatabase>(MongoDatabaseName)) |
|||
.As<IPersistedGrantStore>() |
|||
.SingleInstance(); |
|||
|
|||
builder.RegisterType<MongoContentRepository>() |
|||
.WithParameter(ResolvedParameter.ForNamed<IMongoDatabase>(MongoDatabaseName)) |
|||
.As<IContentRepository>() |
|||
.As<ICatchEventConsumer>() |
|||
.As<IReplayableStore>() |
|||
.SingleInstance(); |
|||
|
|||
builder.RegisterType<MongoHistoryEventRepository>() |
|||
.WithParameter(ResolvedParameter.ForNamed<IMongoDatabase>(MongoDatabaseName)) |
|||
.As<IHistoryEventRepository>() |
|||
.As<ICatchEventConsumer>() |
|||
.As<IReplayableStore>() |
|||
.SingleInstance(); |
|||
|
|||
builder.RegisterType<MongoSchemaRepository>() |
|||
.WithParameter(ResolvedParameter.ForNamed<IMongoDatabase>(MongoDatabaseName)) |
|||
.As<ISchemaRepository>() |
|||
.As<ICatchEventConsumer>() |
|||
.As<IReplayableStore>() |
|||
.SingleInstance(); |
|||
|
|||
builder.RegisterType<MongoAppRepository>() |
|||
.WithParameter(ResolvedParameter.ForNamed<IMongoDatabase>(MongoDatabaseName)) |
|||
.As<IAppRepository>() |
|||
.As<ICatchEventConsumer>() |
|||
.As<IReplayableStore>() |
|||
.SingleInstance(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,28 +0,0 @@ |
|||
// ==========================================================================
|
|||
// MongoDbEventStoreModule.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Autofac; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.MongoDb.EventStore; |
|||
|
|||
namespace Squidex.Config.EventStore |
|||
{ |
|||
public class MongoDbEventStoreModule : Module |
|||
{ |
|||
protected override void Load(ContainerBuilder builder) |
|||
{ |
|||
builder.RegisterType<MongoEventStore>() |
|||
.As<IEventStore>() |
|||
.SingleInstance(); |
|||
|
|||
builder.RegisterType<DefaultNameResolver>() |
|||
.As<IStreamNameResolver>() |
|||
.SingleInstance(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,15 +0,0 @@ |
|||
// ==========================================================================
|
|||
// MyRabbitMqOptions.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Config.EventStore |
|||
{ |
|||
public sealed class MyRabbitMqOptions |
|||
{ |
|||
public string ConnectionString { get; set; } |
|||
} |
|||
} |
|||
@ -1,39 +0,0 @@ |
|||
// ==========================================================================
|
|||
// RabbitMqEventChannelModule.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Autofac; |
|||
using Microsoft.Extensions.Options; |
|||
using RabbitMQ.Client; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.RabbitMq; |
|||
|
|||
namespace Squidex.Config.EventStore |
|||
{ |
|||
public class RabbitMqEventChannelModule : Module |
|||
{ |
|||
protected override void Load(ContainerBuilder builder) |
|||
{ |
|||
builder.Register(context => |
|||
{ |
|||
var options = context.Resolve<IOptions<MyRabbitMqOptions>>().Value; |
|||
|
|||
var factory = new ConnectionFactory(); |
|||
|
|||
factory.SetUri(new Uri(options.ConnectionString)); |
|||
|
|||
return factory; |
|||
}).As<IConnectionFactory>().SingleInstance(); |
|||
|
|||
builder.RegisterType<RabbitMqEventChannel>() |
|||
.As<IEventPublisher>() |
|||
.As<IEventStream>() |
|||
.SingleInstance(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,18 +1,32 @@ |
|||
{ |
|||
"urls": { |
|||
"baseUrl": "http://localhost:5000" |
|||
}, |
|||
"stores": { |
|||
"mongoDb": { |
|||
"connectionString": "mongodb://localhost", |
|||
"databaseName": "Squidex" |
|||
"squidex": { |
|||
"urls": { |
|||
"baseUrl": "http://localhost:5000" |
|||
}, |
|||
"rabbitMq": { |
|||
"connectionString": "amqp://guest:guest@localhost/" |
|||
"eventBus": { |
|||
"type": "rabbitMq", |
|||
"rabbitMq": { |
|||
"connectionString": "amqp://guest:guest@localhost" |
|||
}, |
|||
"catch": true |
|||
}, |
|||
"eventStore": { |
|||
"type": "mongoDb", |
|||
"mongoDb": { |
|||
"connectionString": "mongodb://localhost", |
|||
"databaseName": "Squidex" |
|||
} |
|||
}, |
|||
"stores": { |
|||
"type": "mongoDb", |
|||
"mongoDb": { |
|||
"connectionString": "mongodb://localhost", |
|||
"databaseName": "Squidex" |
|||
} |
|||
}, |
|||
"identity": { |
|||
"googleClient": "1006817248705-t3lb3ge808m9am4t7upqth79hulk456l.apps.googleusercontent.com", |
|||
"googleSecret": "QsEi-fHqkGw2_PjJmtNHf2wg" |
|||
} |
|||
}, |
|||
"identity": { |
|||
"googleClient": "1006817248705-t3lb3ge808m9am4t7upqth79hulk456l.apps.googleusercontent.com", |
|||
"googleSecret": "QsEi-fHqkGw2_PjJmtNHf2wg" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue