Commit 7b305c9c by dingsongjie

application 紧密集成 可靠消息

parent fe4ff39e
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Product.Api.Application.IntergrationEvent
{
public class ProductAddedIntegrationEvent
{
public string ProductName { get; set; }
public long Price { get; set; }
}
}
...@@ -48,9 +48,8 @@ namespace Product.Api ...@@ -48,9 +48,8 @@ namespace Product.Api
option.AutoInjectionDependency(); option.AutoInjectionDependency();
option.AutoInjectionCommandHandlersAndDomainEventHandlers(); option.AutoInjectionCommandHandlersAndDomainEventHandlers();
option.AddPoleEntityFrameworkCoreDomain(); option.AddPoleEntityFrameworkCoreDomain();
});
services.AddPoleReliableMessage(option => option.AddPoleReliableMessage(option =>
{ {
option.AddMasstransitRabbitmq(rabbitoption => option.AddMasstransitRabbitmq(rabbitoption =>
{ {
...@@ -68,6 +67,7 @@ namespace Product.Api ...@@ -68,6 +67,7 @@ namespace Product.Api
.AddEventHandlerAssemblies(typeof(Startup).Assembly); .AddEventHandlerAssemblies(typeof(Startup).Assembly);
option.NetworkInterfaceGatewayAddress = Configuration["ReliableMessageOption:NetworkInterfaceGatewayAddress"]; option.NetworkInterfaceGatewayAddress = Configuration["ReliableMessageOption:NetworkInterfaceGatewayAddress"];
}); });
});
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
using MediatR; using MediatR;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Pole.Application; using Pole.Application;
using Pole.Application.Cqrs;
using Pole.Application.MediatR; using Pole.Application.MediatR;
using Pole.Core.DependencyInjection; using Pole.Core.DependencyInjection;
using Pole.ReliableMessage;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection
{ {
public static class PoleOptionsExtensions public static class PoleOptionsExtensions
{ {
public static PoleOptions AddManageredAssemblies(this PoleOptions options, params Assembly [] assemblies) public static PoleOptions AddManageredAssemblies(this PoleOptions options, params Assembly[] assemblies)
{ {
options.ApplicationAssemblies = assemblies; options.ApplicationAssemblies = assemblies;
return options; return options;
} }
public static PoleOptions AutoInjectionDependency(this PoleOptions 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"); var assemblies = options.ApplicationAssemblies ?? throw new Exception("Cant't find ApplicationAssemblies,You must Run PoleOptions.AddManageredAssemblies First");
foreach (var assembly in assemblies) foreach (var assembly in assemblies)
{ {
...@@ -41,14 +39,19 @@ namespace Microsoft.Extensions.DependencyInjection ...@@ -41,14 +39,19 @@ namespace Microsoft.Extensions.DependencyInjection
}, assemblies.ToArray()); }, assemblies.ToArray());
return options; 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) private static void AddScoped(PoleOptions options, Assembly assembly)
{ {
var implements = assembly.GetTypes().Where(m => typeof(IScopedDenpendency).IsAssignableFrom(m) && m.IsClass && !m.IsAbstract); var implements = assembly.GetTypes().Where(m => typeof(IScopedDenpendency).IsAssignableFrom(m) && m.IsClass && !m.IsAbstract);
foreach (var implement in implements) foreach (var implement in implements)
{ {
var services = implement.GetInterfaces(); var services = implement.GetInterfaces();
foreach(var queriesService in services) foreach (var queriesService in services)
{ {
options.Services.AddScoped(queriesService, implement); options.Services.AddScoped(queriesService, implement);
} }
...@@ -80,5 +83,6 @@ namespace Microsoft.Extensions.DependencyInjection ...@@ -80,5 +83,6 @@ namespace Microsoft.Extensions.DependencyInjection
} }
} }
} }
#endregion
} }
} }
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