Commit c04f65c8 authored by yangxiaodong's avatar yangxiaodong

refactor

parent c1b1509e
...@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Builder ...@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Builder
/// </summary> /// </summary>
public static class BuilderExtensions public static class BuilderExtensions
{ {
/// <summary> ///<summary>
/// Enables Consistence for the current application /// Enables Consistence for the current application
/// </summary> /// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param> /// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param>
...@@ -22,32 +22,18 @@ namespace Microsoft.AspNetCore.Builder ...@@ -22,32 +22,18 @@ namespace Microsoft.AspNetCore.Builder
} }
var marker = app.ApplicationServices.GetService<ConsistencyMarkerService>(); var marker = app.ApplicationServices.GetService<ConsistencyMarkerService>();
if (marker == null) {
throw new InvalidOperationException("Add Consistency must be called on the service collection.");
}
return app;
}
public static IApplicationBuilder UserRouter(this IApplicationBuilder builder, ITopicRoute router) {
if (builder == null) {
throw new ArgumentNullException(nameof(builder));
}
if (router == null) {
throw new ArgumentNullException(nameof(router));
}
var marker = builder.ApplicationServices.GetService<ConsistencyMarkerService>();
if (marker == null) { if (marker == null) {
throw new InvalidOperationException("Add Consistency must be called on the service collection."); throw new InvalidOperationException("Add Consistency must be called on the service collection.");
} }
var router = app.ApplicationServices.GetService<ITopicRoute>();
var context = new TopicRouteContext(); var context = new TopicRouteContext();
router.RouteAsync(context).Wait(); router.RouteAsync(context).Wait();
return builder; return app;
} }
} }
......
...@@ -7,14 +7,6 @@ namespace Microsoft.AspNetCore.Builder ...@@ -7,14 +7,6 @@ namespace Microsoft.AspNetCore.Builder
/// </summary> /// </summary>
public class ConsistencyOptions public class ConsistencyOptions
{ {
/// <summary> public string BrokerUrlList { get; set; } = "localhost:9092";
/// Gets or sets the <see cref="BrokerOptions"/> for the consistency system.
/// </summary>
public BrokerOptions Broker { get; set; } = new BrokerOptions();
public string BrokerUrlList { get; set; }
} }
} }
\ No newline at end of file
using System; using System;
using Cap.Consistency; using Cap.Consistency;
using Cap.Consistency.Infrastructure;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
...@@ -17,7 +18,7 @@ namespace Microsoft.Extensions.DependencyInjection ...@@ -17,7 +18,7 @@ namespace Microsoft.Extensions.DependencyInjection
/// <param name="services">The services available in the application.</param> /// <param name="services">The services available in the application.</param>
/// <returns>An <see cref="ConsistencyBuilder"/> for application services.</returns> /// <returns>An <see cref="ConsistencyBuilder"/> for application services.</returns>
public static ConsistencyBuilder AddConsistency<TMessage>(this IServiceCollection services) public static ConsistencyBuilder AddConsistency<TMessage>(this IServiceCollection services)
where TMessage : class { where TMessage : ConsistencyMessage {
return services.AddConsistency<TMessage>(setupAction: null); return services.AddConsistency<TMessage>(setupAction: null);
} }
...@@ -28,13 +29,11 @@ namespace Microsoft.Extensions.DependencyInjection ...@@ -28,13 +29,11 @@ namespace Microsoft.Extensions.DependencyInjection
/// <param name="setupAction">An action to configure the <see cref="ConsistencyOptions"/>.</param> /// <param name="setupAction">An action to configure the <see cref="ConsistencyOptions"/>.</param>
/// <returns>An <see cref="ConsistencyBuilder"/> for application services.</returns> /// <returns>An <see cref="ConsistencyBuilder"/> for application services.</returns>
public static ConsistencyBuilder AddConsistency<TMessage>(this IServiceCollection services, Action<ConsistencyOptions> setupAction) public static ConsistencyBuilder AddConsistency<TMessage>(this IServiceCollection services, Action<ConsistencyOptions> setupAction)
where TMessage : class { where TMessage : ConsistencyMessage {
services.TryAddSingleton<ConsistencyMarkerService>(); services.TryAddSingleton<ConsistencyMarkerService>();
services.TryAddScoped<ConsistencyMessageManager<TMessage>, ConsistencyMessageManager<TMessage>>(); services.TryAddScoped<ConsistencyMessageManager<TMessage>, ConsistencyMessageManager<TMessage>>();
services.AddSingleton<KafkaConsistency>();
if (setupAction != null) { if (setupAction != null) {
services.Configure(setupAction); services.Configure(setupAction);
} }
......
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 to comment