Commit c04f65c8 authored by yangxiaodong's avatar yangxiaodong

refactor

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