Browse Source

refactor

master
yangxiaodong 7 years ago
parent
commit
e136a05663
1 changed files with 39 additions and 0 deletions
  1. +39
    -0
      src/Cap.Consistency/Microsoft.AspNetCore.Builder/BuilderExtensions.cs

+ 39
- 0
src/Cap.Consistency/Microsoft.AspNetCore.Builder/BuilderExtensions.cs View File

@@ -0,0 +1,39 @@
using System;
using Cap.Consistency;
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<ITopicRouteHandler>();

var context = new TopicRouteContext();

router.RouteAsync(context);

return app;
}

}
}

Loading…
Cancel
Save