yangxiaodong 7 роки тому
джерело
коміт
c04f65c89c
3 змінених файлів з 9 додано та 32 видалено
  1. +5
    -19
      src/Cap.Consistency/Extensions/BuilderExtensions.cs
  2. +1
    -9
      src/Cap.Consistency/Extensions/ConsistencyOptions.cs
  3. +3
    -4
      src/Cap.Consistency/Extensions/ServiceCollectionExtensions.cs

+ 5
- 19
src/Cap.Consistency/Extensions/BuilderExtensions.cs Переглянути файл

@@ -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;
}

}

+ 1
- 9
src/Cap.Consistency/Extensions/ConsistencyOptions.cs Переглянути файл

@@ -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";
}
}

+ 3
- 4
src/Cap.Consistency/Extensions/ServiceCollectionExtensions.cs Переглянути файл

@@ -1,5 +1,6 @@
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);
}


Завантаження…
Відмінити
Зберегти