mirror of https://github.com/Squidex/squidex.git
15 changed files with 200 additions and 129 deletions
@ -0,0 +1,32 @@ |
|||
// ==========================================================================
|
|||
// InMemoryEventBus.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Reactive.Subjects; |
|||
|
|||
namespace Squidex.Infrastructure.CQRS.Events |
|||
{ |
|||
public class InMemoryEventBus : IEventPublisher, IEventStream |
|||
{ |
|||
private readonly Subject<EventData> subject = new Subject<EventData>(); |
|||
|
|||
public void Dispose() |
|||
{ |
|||
} |
|||
|
|||
public void Publish(EventData eventData) |
|||
{ |
|||
subject.OnNext(eventData); |
|||
} |
|||
|
|||
public void Connect(string queueName, Action<EventData> received) |
|||
{ |
|||
subject.Subscribe(received); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
// ==========================================================================
|
|||
// ConfigurationException.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
|
|||
namespace Squidex.Infrastructure |
|||
{ |
|||
public sealed class ConfigurationException : Exception |
|||
{ |
|||
public ConfigurationException() |
|||
{ |
|||
} |
|||
|
|||
public ConfigurationException(string message) |
|||
: base(message) |
|||
{ |
|||
} |
|||
|
|||
public ConfigurationException(string message, Exception inner) |
|||
: base(message, inner) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,17 +1,17 @@ |
|||
// ==========================================================================
|
|||
// MyMongoDbOptions.cs
|
|||
// ICommand.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Read.MongoDb |
|||
namespace Squidex.Infrastructure |
|||
{ |
|||
public class MyMongoDbOptions |
|||
public interface ICliCommand |
|||
{ |
|||
public string ConnectionString { get; set; } |
|||
string Name { get; } |
|||
|
|||
public string DatabaseName { get; set; } |
|||
void Execute(string[] args); |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
// ==========================================================================
|
|||
// IExternalSystem.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Infrastructure |
|||
{ |
|||
public interface IExternalSystem |
|||
{ |
|||
void CheckConnection(); |
|||
} |
|||
} |
|||
@ -1,100 +0,0 @@ |
|||
// ==========================================================================
|
|||
// MongoDbModule.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Autofac; |
|||
using IdentityServer4.Stores; |
|||
using Microsoft.AspNetCore.Identity; |
|||
using Microsoft.AspNetCore.Identity.MongoDB; |
|||
using Microsoft.Extensions.Options; |
|||
using MongoDB.Driver; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.CQRS.Replay; |
|||
using Squidex.Infrastructure.MongoDb; |
|||
using Squidex.Read.Apps.Repositories; |
|||
using Squidex.Read.Contents.Repositories; |
|||
using Squidex.Read.History.Repositories; |
|||
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.Read.MongoDb |
|||
{ |
|||
public class MongoDbModule : Module |
|||
{ |
|||
protected override void Load(ContainerBuilder builder) |
|||
{ |
|||
RefTokenSerializer.Register(); |
|||
|
|||
builder.Register(context => |
|||
{ |
|||
var options = context.Resolve<IOptions<MyMongoDbOptions>>().Value; |
|||
|
|||
var mongoDbClient = new MongoClient(options.ConnectionString); |
|||
var mongoDatabase = mongoDbClient.GetDatabase(options.DatabaseName); |
|||
|
|||
return mongoDatabase; |
|||
}).SingleInstance(); |
|||
|
|||
builder.Register<IUserStore<IdentityUser>>(context => |
|||
{ |
|||
var usersCollection = context.Resolve<IMongoDatabase>().GetCollection<IdentityUser>("Identity_Users"); |
|||
|
|||
IndexChecks.EnsureUniqueIndexOnNormalizedEmail(usersCollection); |
|||
IndexChecks.EnsureUniqueIndexOnNormalizedUserName(usersCollection); |
|||
|
|||
return new UserStore<IdentityUser>(usersCollection); |
|||
}).SingleInstance(); |
|||
|
|||
builder.Register<IRoleStore<IdentityRole>>(context => |
|||
{ |
|||
var rolesCollection = context.Resolve<IMongoDatabase>().GetCollection<IdentityRole>("Identity_Roles"); |
|||
|
|||
IndexChecks.EnsureUniqueIndexOnNormalizedRoleName(rolesCollection); |
|||
|
|||
return new RoleStore<IdentityRole>(rolesCollection); |
|||
}).SingleInstance(); |
|||
|
|||
builder.RegisterType<MongoPersistedGrantStore>() |
|||
.As<IPersistedGrantStore>() |
|||
.SingleInstance(); |
|||
|
|||
builder.RegisterType<MongoUserRepository>() |
|||
.As<IUserRepository>() |
|||
.InstancePerLifetimeScope(); |
|||
|
|||
builder.RegisterType<MongoContentRepository>() |
|||
.As<IContentRepository>() |
|||
.As<ICatchEventConsumer>() |
|||
.As<IReplayableStore>() |
|||
.SingleInstance(); |
|||
|
|||
builder.RegisterType<MongoHistoryEventRepository>() |
|||
.As<IHistoryEventRepository>() |
|||
.As<ICatchEventConsumer>() |
|||
.As<IReplayableStore>() |
|||
.SingleInstance(); |
|||
|
|||
builder.RegisterType<MongoSchemaRepository>() |
|||
.As<ISchemaRepository>() |
|||
.As<ICatchEventConsumer>() |
|||
.As<IReplayableStore>() |
|||
.SingleInstance(); |
|||
|
|||
builder.RegisterType<MongoAppRepository>() |
|||
.As<IAppRepository>() |
|||
.As<ICatchEventConsumer>() |
|||
.As<IReplayableStore>() |
|||
.SingleInstance(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
// ==========================================================================
|
|||
// MongoDbStoresExternalSystem.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using MongoDB.Driver; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Read.MongoDb |
|||
{ |
|||
public sealed class MongoDbStoresExternalSystem : IExternalSystem |
|||
{ |
|||
private readonly IMongoDatabase database; |
|||
|
|||
public MongoDbStoresExternalSystem(IMongoDatabase database) |
|||
{ |
|||
Guard.NotNull(database, nameof(database)); |
|||
|
|||
this.database = database; |
|||
} |
|||
|
|||
public void CheckConnection() |
|||
{ |
|||
try |
|||
{ |
|||
database.ListCollections(); |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
throw new ConfigurationException($"MongoDb Event Store failed to connect to database {database.DatabaseNamespace.DatabaseName}", e); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue