Browse Source

refactor

master
yangxiaodong 7 years ago
parent
commit
e5d11f1a96
2 changed files with 0 additions and 83 deletions
  1. +0
    -40
      src/Cap.Consistency/Extensions/BuilderExtensions.cs
  2. +0
    -43
      src/Cap.Consistency/Extensions/ServiceCollectionExtensions.cs

+ 0
- 40
src/Cap.Consistency/Extensions/BuilderExtensions.cs View File

@@ -1,40 +0,0 @@
using System;
using Cap.Consistency;
using Cap.Consistency.Routing;
using Microsoft.Extensions.DependencyInjection;

// ReSharper disable once CheckNamespace
namespace Microsoft.AspNetCore.Builder
{
/// <summary>
/// Consistence extensions for <see cref="IApplicationBuilder"/>
/// </summary>
public static class BuilderExtensions
{
///<summary>
/// Enables Consistence for the current application
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param>
/// <returns>The <see cref="IApplicationBuilder"/> instance this method extends.</returns>
public static IApplicationBuilder UseConsistency(this IApplicationBuilder app) {
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.");
}

var router = app.ApplicationServices.GetService<ITopicRoute>();

var context = new TopicRouteContext();

router.RouteAsync(context);

return app;
}

}
}

+ 0
- 43
src/Cap.Consistency/Extensions/ServiceCollectionExtensions.cs View File

@@ -1,43 +0,0 @@
using System;
using Cap.Consistency;
using Cap.Consistency.Infrastructure;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection.Extensions;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Contains extension methods to <see cref="IServiceCollection"/> for configuring consistence services.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds and configures the consistence services for the consitence.
/// </summary>
/// <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 : ConsistencyMessage {
return services.AddConsistency<TMessage>(x => new ConsistencyOptions());
}

/// <summary>
/// Adds and configures the consistence services for the consitence.
/// </summary>
/// <param name="services">The services available in the application.</param>
/// <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 : ConsistencyMessage {
services.TryAddSingleton<ConsistencyMarkerService>();

services.TryAddScoped<ConsistencyMessageManager<TMessage>, ConsistencyMessageManager<TMessage>>();

services.Configure(setupAction);

return new ConsistencyBuilder(typeof(TMessage), services);
}

}
}

Loading…
Cancel
Save