Skip to content

Commit

Permalink
removing domainEvents from BaseDbContext
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEggenberger committed Nov 26, 2024
1 parent bfd213a commit 294f2cc
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 144 deletions.
17 changes: 17 additions & 0 deletions Source/Modules/Channels/Features/ChannelsModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Modules.Channels.Features.Infrastructure.EFCore;
using Shared.Features.Modules;
using System.Reflection;

namespace Modules.Subscriptions.Features
{
public class ChannelsModule : IModule
{
public Assembly FeaturesAssembly => typeof(ChannelsModule).Assembly;
public ChannelsDbContext ChannelsDbContext { get; set; }

public ChannelsModule(ChannelsDbContext dbContext)
{
ChannelsDbContext = dbContext;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
using Modules.Channels.Features.Infrastructure.EFCore;
using Modules.Subscriptions.Features;
using Shared.Features.Messaging.Command;
using Shared.Features.Server;

namespace Modules.Channels.Features.DomainFeatures.Channels.Application.Commands
{
public class DeleteChannel : Command
{
public Guid ChannelId { get; set; }
}
public class DeleteChannelCommandCommandHandler : ICommandHandler<DeleteChannel>
public class DeleteChannelCommandCommandHandler : ServerExecutionBase<ChannelsModule>, ICommandHandler<DeleteChannel>
{
private readonly ChannelsDbContext applicationDbContext;
public DeleteChannelCommandCommandHandler(ChannelsDbContext applicationDbContext)
public DeleteChannelCommandCommandHandler(IServiceProvider serviceProvider) : base(serviceProvider)
{
this.applicationDbContext = applicationDbContext;
}

public async Task HandleAsync(DeleteChannel command, CancellationToken cancellationToken)
{
Channel channel = applicationDbContext.Channels.Single(c => c.Id == command.ChannelId);
applicationDbContext.Channels.Remove(channel);
await applicationDbContext.SaveChangesAsync(cancellationToken);
Channel channel = module.ChannelsDbContext.Channels.Single(c => c.Id == command.ChannelId);
module.ChannelsDbContext.Channels.Remove(channel);
await module.ChannelsDbContext.SaveChangesAsync(cancellationToken);
//await aggregatesUINotifierService.UpdateChannels(teamResolver.ResolveTenant());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
using Modules.Channels.Features.Infrastructure.EFCore;
using Modules.Subscriptions.Features;
using Shared.Features.Messaging.Query;
using Shared.Features.Server;

namespace Modules.Channels.Features.DomainFeatures.Channels.Application.Queries
{
public class GetAllChannels : Query<List<Channel>>
{

}
public class AllChannelsQueryHandler : BaseQueryHandler<ChannelsDbContext, Channel>, IQueryHandler<GetAllChannels, List<Channel>>
public class AllChannelsQueryHandler : ServerExecutionBase<ChannelsModule>, IQueryHandler<GetAllChannels, List<Channel>>
{
public AllChannelsQueryHandler(ChannelsDbContext applicationDbContext) : base(applicationDbContext) { }
public async Task<List<Channel>> HandleAsync(GetAllChannels query, CancellationToken cancellation)
public AllChannelsQueryHandler(IServiceProvider serviceProvider) : base(serviceProvider)
{
return dbSet.ToList();
}

public Task<List<Channel>> HandleAsync(GetAllChannels query, CancellationToken cancellation)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
using Modules.Channels.Features.Infrastructure.EFCore;
using Modules.Subscriptions.Features;
using Shared.Features.Messaging.Query;
using Shared.Features.Server;

namespace Modules.Channels.Features.DomainFeatures.Channels.Application.Queries
{
public class AllMessagesForChannel : Query<List<Channel>>
{

}
public class AllMessagesForChannelQueryHandler : BaseQueryHandler<ChannelsDbContext, Channel>, IQueryHandler<GetAllChannels, List<Channel>>
public class AllMessagesForChannelQueryHandler : ServerExecutionBase<ChannelsModule>, IQueryHandler<GetAllChannels, List<Channel>>
{
public AllMessagesForChannelQueryHandler(ChannelsDbContext applicationDbContext) : base(applicationDbContext) { }
public async Task<List<Channel>> HandleAsync(GetAllChannels query, CancellationToken cancellation)
public AllMessagesForChannelQueryHandler(IServiceProvider serviceProvider) : base(serviceProvider)
{
return dbSet.ToList();
}

public Task<List<Channel>> HandleAsync(GetAllChannels query, CancellationToken cancellation)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
using Microsoft.EntityFrameworkCore;
using Modules.Channels.Features.Infrastructure.EFCore;
using Modules.Subscriptions.Features;
using Shared.Features.Messaging.Query;
using Shared.Features.Server;

namespace Modules.Channels.Features.DomainFeatures.Channels.Application.Queries
{
public class GetChannelById : Query<Channel>
{
public Guid Id { get; set; }
}
public class GetChannelQueryHandler : BaseQueryHandler<ChannelsDbContext, Channel>, IQueryHandler<GetChannelById, Channel>
public class GetChannelQueryHandler : ServerExecutionBase<ChannelsModule>, IQueryHandler<GetChannelById, Channel>
{
public GetChannelQueryHandler(ChannelsDbContext applicationDbContext) : base(applicationDbContext) { }
public GetChannelQueryHandler(IServiceProvider serviceProvider) : base(serviceProvider)
{
}

public Task<Channel> HandleAsync(GetChannelById query, CancellationToken cancellation)
{
return dbSet.SingleAsync(c => c.Id == query.Id);
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Modules.Channels.Features.DomainFeatures.Channels
{
public class Channel : AggregateRoot
public class Channel : Entity
{
public string Name { get; set; }
public string Goal { get; set; }
Expand All @@ -23,12 +23,10 @@ public Channel(string name, string goal, bool messagesAreAnonymous)
public void AddMessage(Message message)
{
messages.Add(message);
AddDomainEvent(new ChannelMessagesUpdatedEvent());
}
public void RemoveMessage(Message message)
{
messages.Remove(messages.Single(m => m.Id == message.Id));
AddDomainEvent(new ChannelMessagesUpdatedEvent());
}
public void AddMessageVote(Message message, Reaction vote)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace Web.Server.Controllers.Stripe
public class StripeWebhook : BaseController
{
private readonly StripeOptions stripeOptions;
private readonly ICommandDispatcher commandDispatcher;
public StripeWebhook(IOptions<StripeOptions> stripeOptions, ICommandDispatcher commandDispatcher)
{
this.stripeOptions = stripeOptions.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Modules.TenantIdentity.Features.Infrastructure.EFCore;
using Shared.Features.Messaging.Query;
using Shared.Features.Server;
using System;
using System.Linq;
using System.Threading;
Expand All @@ -12,12 +13,15 @@ public class GetTenantMembershipQuery : Query<TenantMembership>
public Guid UserId { get; set; }
public Guid TenantId { get; set; }
}
public class GetTenantMembershipQueryHandler : BaseQueryHandler<TenantIdentityDbContext, Tenant>, IQueryHandler<GetTenantMembershipQuery, TenantMembership>
public class GetTenantMembershipQueryHandler : ServerExecutionBase<TenantIdentityModule>, IQueryHandler<GetTenantMembershipQuery, TenantMembership>
{
public GetTenantMembershipQueryHandler(TenantIdentityDbContext tenantDbContext) : base(tenantDbContext) { }
public async Task<TenantMembership> HandleAsync(GetTenantMembershipQuery query, CancellationToken cancellation)
public GetTenantMembershipQueryHandler(IServiceProvider serviceProvider) : base(serviceProvider)
{
return dbSet.First().Memberships.Single(m => m.UserId == query.UserId);
}

public Task<TenantMembership> HandleAsync(GetTenantMembershipQuery query, CancellationToken cancellation)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Modules.TenantIdentity.Features.Infrastructure.EFCore;
using Shared.Features.Messaging.Command;
using Shared.Features.Server;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -11,17 +12,15 @@ public class SetSelectedTenantForUser : Command
public Guid SelectedTenantId { get; set; }
public Guid UserId { get; set; }
}
public class SetSelectedTenantForUserHandler : ICommandHandler<SetSelectedTenantForUser>
public class SetSelectedTenantForUserHandler : ServerExecutionBase<TenantIdentityModule>, ICommandHandler<SetSelectedTenantForUser>
{
private readonly TenantIdentityDbContext tenantIdentityDbContext;
public SetSelectedTenantForUserHandler(TenantIdentityDbContext tenantIdentityDbContext)
public SetSelectedTenantForUserHandler(IServiceProvider serviceProvider) : base(serviceProvider)
{
this.tenantIdentityDbContext = tenantIdentityDbContext;
}

public async Task HandleAsync(SetSelectedTenantForUser command, CancellationToken cancellationToken)
{
var user = await tenantIdentityDbContext.GetUserByIdAsync(command.UserId);
var user = await module.TenantIdentityDbContext.GetUserByIdAsync(command.UserId);

if (user.SelectedTenantId == command.SelectedTenantId)
{
Expand All @@ -30,7 +29,7 @@ public async Task HandleAsync(SetSelectedTenantForUser command, CancellationToke

user.SelectedTenantId = command.SelectedTenantId;

await tenantIdentityDbContext.SaveChangesAsync(cancellationToken);
await module.TenantIdentityDbContext.SaveChangesAsync(cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Modules.TenantIdentity.Features.Infrastructure.EFCore;
using Shared.Features.Messaging.Query;
using Shared.Features.Server;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -10,17 +11,15 @@ public class GetUserById : Query<ApplicationUser>
{
public Guid UserId { get; set; }
}
public class GetUserByIdHandler : IQueryHandler<GetUserById, ApplicationUser>
public class GetUserByIdHandler : ServerExecutionBase<TenantIdentityModule>, IQueryHandler<GetUserById, ApplicationUser>
{
private readonly TenantIdentityDbContext tenantIdentityDbContext;
public GetUserByIdHandler(TenantIdentityDbContext tenantIdentityDbContext)
public GetUserByIdHandler(IServiceProvider serviceProvider) : base(serviceProvider)
{
this.tenantIdentityDbContext = tenantIdentityDbContext;
}

public async Task<ApplicationUser> HandleAsync(GetUserById query, CancellationToken cancellation)
{
return await tenantIdentityDbContext.GetUserByIdAsync(query.UserId);
return await module.TenantIdentityDbContext.GetUserByIdAsync(query.UserId);
}
}
}
Loading

0 comments on commit 294f2cc

Please sign in to comment.