Add project files.

This commit is contained in:
2025-09-01 13:34:36 +04:30
parent 1f2fb6e2d7
commit 81e43f5b92
83 changed files with 1733 additions and 0 deletions
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using VizhTalk.Learning.Application;
namespace VizhTalk.Learning.Infrastructure.Configuration
{
public static class Assemblies
{
public static Assembly Infrastructure = typeof(LearningStartup).Assembly;
public static Assembly Application = typeof(ILearningModule).Assembly;
}
}
@@ -0,0 +1,48 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using VizhTalk.BuildingBlocks.Application.Configuration.Commnad;
using VizhTalk.BuildingBlocks.Application.Contract;
using VizhTalk.BuildingBlocks.Domain;
using VizhTalk.BuildingBlocks.Domain.Contract;
using VizhTalk.Learning.Application;
namespace VizhTalk.Learning.Infrastructure.Configuration;
public class LearningModule(IServiceProvider serviceProvider) : ILearningModule
{
public async Task Execute(ICommand command, CancellationToken cancellationToken = default)
{
var handlerType = typeof(ICommandHandler<>).MakeGenericType(command.GetType());
var handler = serviceProvider.GetRequiredService(handlerType);
dynamic dynamicHandler = handler;
dynamic dynamicCommand = command;
await dynamicHandler.Handle(dynamicCommand, cancellationToken);
}
public async Task<TResult> Execute<TResult>(ICommand<TResult> command, CancellationToken cancellationToken = default)
{
var handlerType = typeof(ICommandHandler<,>).MakeGenericType(command.GetType());
var handler = serviceProvider.GetRequiredService(handlerType);
dynamic dynamicHandler = handler;
dynamic dynamicCommand = command;
return await dynamicHandler.Handle(dynamicCommand, cancellationToken);
}
public async Task<TResult> Execute<TResult>(IQuery<TResult> query, CancellationToken cancellationToken = default)
{
var handlerType = typeof(ICommandHandler<,>).MakeGenericType(query.GetType());
var handler = serviceProvider.GetRequiredService(handlerType);
dynamic dynamicHandler = handler;
dynamic dynamicQuery = query;
return await dynamicHandler.Handle(dynamicQuery, cancellationToken);
}
public async Task Execute(IDomainEvent notification, CancellationToken cancellationToken = default)
{
var handlerType = typeof(INotificationHandler<>).MakeGenericType(notification.GetType());
var handler = serviceProvider.GetRequiredService(handlerType);
dynamic dynamicHandler = handler;
dynamic dynamicNotification = notification;
await dynamicHandler.Handle(dynamicNotification, cancellationToken);
}
}
@@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using VizhTalk.BuildingBlocks.Infrastructure.EF.Helpers;
namespace VizhTalk.Learning.Infrastructure.EF;
public class LearningDbContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.FindEntities()
.PluralizeEntities();
}
}
@@ -0,0 +1,60 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using VizhTalk.BuildingBlocks.Application.Configuration.Commnad;
using VizhTalk.BuildingBlocks.Application.Configuration.Query;
using VizhTalk.BuildingBlocks.Application.Events;
using VizhTalk.BuildingBlocks.Application.Outbox;
using VizhTalk.BuildingBlocks.Infrastructure;
using VizhTalk.BuildingBlocks.Infrastructure.DomainEventsDispatching;
using VizhTalk.Learning.Application;
using VizhTalk.Learning.Infrastructure.Configuration;
using VizhTalk.Learning.Infrastructure.EF;
namespace VizhTalk.Learning.Infrastructure;
public static class LearningStartup
{
public static void Initialize(this IServiceCollection services, string connectionString)
{
services.AddDbContext<LearningDbContext>(op =>
{
op.UseSqlServer(connectionString);
});
services.AddScoped<ILearningModule, LearningModule>();
services.AddScoped<IExecutor, LearningModule>();
services.AddScoped<IUnitOfWork, UnitOfWork>();
services.AddScoped<IDomainEventsAccessor, DomainEventsAccessor>();
services.AddScoped<IDomainEventsDispatcher, DomainEventsDispatcher>();
services.AddScoped<IDomainNotificationsMapper, DomainNotificationsMapper>();
services.Scan(scan => scan.
FromAssemblies(Assemblies.Application, Assemblies.Infrastructure)
.AddClasses(classes => classes.AssignableTo(typeof(ICommandHandler<>)), publicOnly: false)
.AsImplementedInterfaces()
.WithScopedLifetime()
.AddClasses(classes => classes.AssignableTo(typeof(ICommandHandler<,>)), publicOnly: false)
.AsImplementedInterfaces()
.WithScopedLifetime()
.AddClasses(classes => classes.AssignableTo(typeof(IQueryHandler<,>)), publicOnly: false)
.AsImplementedInterfaces()
.WithScopedLifetime()
.AddClasses(classes => classes.AssignableTo(typeof(ICommandHandler<>)), publicOnly: false)
.AsImplementedInterfaces()
.WithScopedLifetime());
services.Decorate(typeof(ICommandHandler<>), typeof(UnitOfWorkCommandHandlerDecorator<>));
services.AddScoped(sa =>
{
var notifications = sa.GetServices<IDomainEventNotification>();
var notificationDic = new BiDictionary<string, Type>();
foreach (var notification in notifications)
notificationDic.Add(notification!.ToString()!, notification!.GetType());
return notificationDic;
});
services.AddScoped<IOutbox>(sa =>
{
return null; // ToDo
});
}
}
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VizhTalk.BuildingBlocks.Application.Outbox;
namespace VizhTalk.Learning.Infrastructure.Outbox
{
public class OutboxAccessor : IOutbox
{
public OutboxAccessor()
{
}
public void Add(OutboxMessage message)
{
throw new NotImplementedException();
}
public Task Save()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\VizhTalk.BuildingBlocks.Infrastructure\VizhTalk.BuildingBlocks.Infrastructure.csproj" />
<ProjectReference Include="..\VizhTalk.Learning.Application\VizhTalk.Learning.Application.csproj" />
</ItemGroup>
</Project>