Commit 0d514eaf by dingsongjie

删除不必要的项目

parent 09045920
......@@ -9,8 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{655E719B-4
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.Core", "src\Pole.Core\Pole.Core.csproj", "{CA80F6EF-95A0-4BB7-BA8B-02E167E82865}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.Application", "src\Pole.Application\Pole.Application.csproj", "{C7825E5B-4FB0-4498-B8D1-E9EC0BC1AA5C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.Grpc", "src\Pole.Grpc\Pole.Grpc.csproj", "{F40FE25F-6081-4B29-A7BD-CB5C24F6FDA8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{4A0FB696-EC29-4A5F-B40B-A6FC56001ADB}"
......@@ -39,7 +37,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.EventStorage.PostgreSq
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.Orleans.Provider.EntityframeworkCore", "src\Pole.Orleans.Provider.EntityframeworkCore\Pole.Orleans.Provider.EntityframeworkCore.csproj", "{0DA75F4A-BF47-4B52-B932-48BB6A709934}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pole.Samples.Backet.Api", "test\Pole.Samples.Backet.Api\Pole.Samples.Backet.Api.csproj", "{FB3D2F52-123A-4606-B682-9159BD7913AE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.Samples.Backet.Api", "test\Pole.Samples.Backet.Api\Pole.Samples.Backet.Api.csproj", "{FB3D2F52-123A-4606-B682-9159BD7913AE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -51,10 +49,6 @@ Global
{CA80F6EF-95A0-4BB7-BA8B-02E167E82865}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA80F6EF-95A0-4BB7-BA8B-02E167E82865}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA80F6EF-95A0-4BB7-BA8B-02E167E82865}.Release|Any CPU.Build.0 = Release|Any CPU
{C7825E5B-4FB0-4498-B8D1-E9EC0BC1AA5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7825E5B-4FB0-4498-B8D1-E9EC0BC1AA5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7825E5B-4FB0-4498-B8D1-E9EC0BC1AA5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7825E5B-4FB0-4498-B8D1-E9EC0BC1AA5C}.Release|Any CPU.Build.0 = Release|Any CPU
{F40FE25F-6081-4B29-A7BD-CB5C24F6FDA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F40FE25F-6081-4B29-A7BD-CB5C24F6FDA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F40FE25F-6081-4B29-A7BD-CB5C24F6FDA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
......@@ -105,7 +99,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CA80F6EF-95A0-4BB7-BA8B-02E167E82865} = {9932C965-8B38-4F70-9E43-86DC56860E2B}
{C7825E5B-4FB0-4498-B8D1-E9EC0BC1AA5C} = {9932C965-8B38-4F70-9E43-86DC56860E2B}
{F40FE25F-6081-4B29-A7BD-CB5C24F6FDA8} = {9932C965-8B38-4F70-9E43-86DC56860E2B}
{475116FC-DEEC-4255-94E4-AE7B8C85038D} = {4A0FB696-EC29-4A5F-B40B-A6FC56001ADB}
{452B9D9E-881E-4E0E-A90B-98F2253F20F1} = {4A0FB696-EC29-4A5F-B40B-A6FC56001ADB}
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Application.Command
{
public class Command<TRequest,TResponse>:ICommand<TResponse>
{
public Command(TRequest request)
{
Data = request;
}
public TRequest Data { get; private set; }
}
}
using MediatR;
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Application.Command
{
public interface ICommand<TResponse>:IRequest<TResponse>
{
}
}
using MediatR;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Pole.Application.Command
{
public interface ICommandBus
{
Task<TResult> Send<TResult>(IRequest<TResult> request, CancellationToken cancellationToken = default);
Task<object> Send(object request, CancellationToken cancellationToken = default);
}
}
using MediatR;
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Application.Command
{
public interface ICommandHandler<TCommand,TResult>: IRequestHandler<TCommand, TResult> where TCommand : ICommand<TResult>
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Pole.Application.Command;
namespace Pole.Application.Cqrs.Internal
{
class DefaultCommandBus : ICommandBus
{
private readonly IMediator _mediator;
public DefaultCommandBus(IMediator mediator)
{
_mediator = mediator;
}
public Task<TResult> Send<TResult>(IRequest<TResult> request, CancellationToken cancellationToken = default)
{
return _mediator.Send(request, cancellationToken);
}
public Task<object> Send(object request, CancellationToken cancellationToken = default)
{
return _mediator.Send(request, cancellationToken);
}
}
}
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Pole.Application.EventBus
{
public class DefaultReliableMessageScopedBuffer : IReliableMessageScopedBuffer
{
public ConcurrentBag<EventEntry> EventEntries = new ConcurrentBag<EventEntry>();
public void Add(EventEntry eventEntry)
{
EventEntries.Add(eventEntry);
}
public IEnumerable<EventEntry> GetAll()
{
return EventEntries.AsEnumerable();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Application.EventBus
{
public class EventEntry
{
public object Event { get;private set; }
public object CallbackParemeter { get; private set; }
public string PrePublishEventId { get; set; }
public Type EventType { get;private set; }
public EventEntry(object @event,object callbackParemeter, Type eventType)
{
Event = @event;
CallbackParemeter = callbackParemeter;
EventType = eventType;
}
}
}
using Pole.ReliableMessage.Masstransit;
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Application.EventBus
{
public abstract class IntegrationEventHandler<TEvent> : ReliableEventHandler<TEvent> where TEvent : class
{
public IntegrationEventHandler(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Pole.Application.EventBus
{
public interface IBus
{
Task Publish<TReliableEvent>(TReliableEvent @event, object callbackParemeter, CancellationToken cancellationToken = default) where TReliableEvent : class;
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Pole.Application.EventBus
{
public interface IEventBus
{
Task Publish<TReliableEvent>(TReliableEvent @event, object callbackParemeter, CancellationToken cancellationToken = default) where TReliableEvent : class;
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Application.EventBus
{
public interface IReliableMessageScopedBuffer
{
void Add(EventEntry eventEntry);
IEnumerable<EventEntry> GetAll();
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Pole.Application.EventBus
{
public class ReliableEventBus : IEventBus
{
private readonly IReliableMessageScopedBuffer _reliableMessageScopedBuffer;
public ReliableEventBus(IReliableMessageScopedBuffer reliableMessageScopedBuffer)
{
_reliableMessageScopedBuffer = reliableMessageScopedBuffer;
}
public Task Publish<TReliableEvent>(TReliableEvent @event, object callbackParemeter, CancellationToken cancellationToken = default) where TReliableEvent : class
{
_reliableMessageScopedBuffer.Add(new EventEntry(@event, callbackParemeter,typeof(TReliableEvent)));
return Task.FromResult(1);
}
}
}
using Microsoft.Extensions.Logging;
using Pole.Domain.UnitOfWork;
using Pole.ReliableMessage.Abstraction;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Pole.Application.EventBus
{
public class ReliableMessageTransactionWorker : IWorker
{
private readonly IReliableMessageScopedBuffer _reliableMessageScopedBuffer;
private readonly IReliableBus _reliableBus;
private readonly ILogger<ReliableMessageTransactionWorker> _logger;
public ReliableMessageTransactionWorker(IReliableMessageScopedBuffer reliableMessageScopedBuffer, IReliableBus reliableBus, ILogger<ReliableMessageTransactionWorker> logger)
{
_reliableMessageScopedBuffer = reliableMessageScopedBuffer;
_reliableBus = reliableBus;
_logger = logger;
}
public int Order => 200;
public WorkerStatus WorkerStatus { get; set; }
public async Task Commit(CancellationToken cancellationToken = default)
{
var events = _reliableMessageScopedBuffer.GetAll();
try
{
var tasks = events.Select(async @event =>
{
await _reliableBus.Publish(@event.Event, @event.PrePublishEventId, cancellationToken);
});
await Task.WhenAll(tasks);
}
catch (Exception ex)
{
_logger.LogError(ex, "ReliableMessageTransactionWorker.Commit error");
// 此时 预发送成功 ,数据库事务提交成功 ,发送消息至消息队列失败 ,任然返回成功 ,因为预发送消息 的重试机制会让 消息发送成功
}
WorkerStatus = WorkerStatus.Commited;
return;
}
public void Dispose()
{
}
public async Task PreCommit(CancellationToken cancellationToken = default)
{
var events = _reliableMessageScopedBuffer.GetAll();
foreach (var @event in events)
{
@event.PrePublishEventId = await _reliableBus.PrePublish(@event.Event, @event.EventType, @event.CallbackParemeter, cancellationToken);
}
WorkerStatus = WorkerStatus.PreCommited;
}
public Task Rollback(CancellationToken cancellationToken = default)
{
var events = _reliableMessageScopedBuffer.GetAll();
events.Where(m => !string.IsNullOrEmpty(m.PrePublishEventId)).ToList().ForEach(async @event =>
{
await _reliableBus.Cancel(@event.PrePublishEventId, cancellationToken);
});
WorkerStatus = WorkerStatus.Rollbacked;
return Task.FromResult(1);
}
}
}
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Application.MediatR
{
public static class MediatRServiceConfigurationExtensions
{
public static MediatRServiceConfiguration AddServiceLifetime(this MediatRServiceConfiguration configuration, ServiceLifetime lifetime)
{
if (lifetime == ServiceLifetime.Scoped)
{
configuration.AsScoped();
}
else if (lifetime == ServiceLifetime.Singleton)
{
configuration.AsSingleton();
}
else
{
configuration.AsTransient();
}
return configuration;
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Pole.Core\Pole.Core.csproj" />
<ProjectReference Include="..\Pole.Domain\Pole.Domain.csproj" />
<ProjectReference Include="..\Pole.ReliableMessage.Masstransit\Pole.ReliableMessage.Masstransit.csproj" />
<ProjectReference Include="..\Pole.ReliableMessage\Pole.ReliableMessage.csproj" />
</ItemGroup>
</Project>
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace Pole.Application
{
public class PoleOptions
{
public PoleOptions(IServiceCollection services)
{
Services = services;
}
public IServiceCollection Services { get;private set; }
public IEnumerable<Assembly> ApplicationAssemblies { get; set; }
}
}
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using Pole.Application;
using Pole.Application.MediatR;
using Pole.Core.DependencyInjection;
using Pole.ReliableMessage;
using System;
using System.Linq;
using System.Reflection;
namespace Microsoft.Extensions.DependencyInjection
{
public static class PoleOptionsExtensions
{
public static PoleOptions AddManageredAssemblies(this PoleOptions options, params Assembly[] assemblies)
{
options.ApplicationAssemblies = assemblies;
return options;
}
public static PoleOptions AutoInjectionDependency(this PoleOptions options)
{
var assemblies = options.ApplicationAssemblies ?? throw new Exception("Cant't find ApplicationAssemblies,You must Run PoleOptions.AddManageredAssemblies First");
foreach (var assembly in assemblies)
{
AddScoped(options, assembly);
AddTransient(options, assembly);
AddSingleton(options, assembly);
}
return options;
}
public static PoleOptions AutoInjectionCommandHandlersAndDomainEventHandlers(this PoleOptions options, ServiceLifetime lifetime = ServiceLifetime.Scoped)
{
var assemblies = options.ApplicationAssemblies ?? throw new Exception("Cant't find ApplicationAssemblies,You must Run PoleOptions.AddManageredAssemblies First");
options.Services.AddMediatR(config =>
{
config.AddServiceLifetime(lifetime);
}, assemblies.ToArray());
return options;
}
public static PoleOptions AddPoleReliableMessage(this PoleOptions options, Action<ReliableMessageOption> optionConfig)
{
options.Services.AddPoleReliableMessage(optionConfig);
return options;
}
#region Internal
private static void AddScoped(PoleOptions options, Assembly assembly)
{
var implements = assembly.GetTypes().Where(m => typeof(IScopedDenpendency).IsAssignableFrom(m) && m.IsClass && !m.IsAbstract);
foreach (var implement in implements)
{
var services = implement.GetInterfaces();
foreach (var queriesService in services)
{
options.Services.AddScoped(queriesService, implement);
}
}
}
private static void AddTransient(PoleOptions options, Assembly assembly)
{
var implements = assembly.GetTypes().Where(m => typeof(ITransientDependency).IsAssignableFrom(m) && m.IsClass && !m.IsAbstract);
foreach (var implement in implements)
{
var services = implement.GetInterfaces();
foreach (var queriesService in services)
{
options.Services.AddTransient(queriesService, implement);
}
}
}
private static void AddSingleton(PoleOptions options, Assembly assembly)
{
var implements = assembly.GetTypes().Where(m => typeof(ISingleDependency).IsAssignableFrom(m) && m.IsClass && !m.IsAbstract);
foreach (var implement in implements)
{
var services = implement.GetInterfaces();
foreach (var queriesService in services)
{
options.Services.AddSingleton(queriesService, implement);
}
}
}
#endregion
}
}
using Pole.Core.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Application.Query
{
public interface IQueries: IScopedDenpendency
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
using MediatR;
using System.Reflection;
using Pole.Application.Cqrs;
using Pole.Application.Cqrs.Internal;
using Pole.Application.Command;
using Pole.Application;
using Pole.Domain.UnitOfWork;
using Pole.Application.EventBus;
namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddPole(this IServiceCollection services, Action<PoleOptions> config)
{
PoleOptions poleOptions = new PoleOptions(services);
config(poleOptions);
services.AddScoped<ICommandBus, DefaultCommandBus>();
services.AddScoped<IUnitOfWork, DefaultUnitOfWork>();
services.AddScoped<IWorker, ReliableMessageTransactionWorker>();
services.AddScoped<IEventBus, ReliableEventBus>();
services.AddScoped<IReliableMessageScopedBuffer, DefaultReliableMessageScopedBuffer>();
return services;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment