From e136a0566317888e5f3743e147ff2a25c729400d Mon Sep 17 00:00:00 2001 From: yangxiaodong Date: Mon, 5 Jun 2017 11:36:52 +0800 Subject: [PATCH] refactor --- .../BuilderExtensions.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Cap.Consistency/Microsoft.AspNetCore.Builder/BuilderExtensions.cs diff --git a/src/Cap.Consistency/Microsoft.AspNetCore.Builder/BuilderExtensions.cs b/src/Cap.Consistency/Microsoft.AspNetCore.Builder/BuilderExtensions.cs new file mode 100644 index 0000000..da6058f --- /dev/null +++ b/src/Cap.Consistency/Microsoft.AspNetCore.Builder/BuilderExtensions.cs @@ -0,0 +1,39 @@ +using System; +using Cap.Consistency; +using Microsoft.Extensions.DependencyInjection; + +// ReSharper disable once CheckNamespace +namespace Microsoft.AspNetCore.Builder +{ + /// + /// Consistence extensions for + /// + public static class BuilderExtensions + { + /// + /// Enables Consistence for the current application + /// + /// The instance this method extends. + /// The instance this method extends. + public static IApplicationBuilder UseConsistency(this IApplicationBuilder app) { + if (app == null) { + throw new ArgumentNullException(nameof(app)); + } + + var marker = app.ApplicationServices.GetService(); + + if (marker == null) { + throw new InvalidOperationException("Add Consistency must be called on the service collection."); + } + + var router = app.ApplicationServices.GetService(); + + var context = new TopicRouteContext(); + + router.RouteAsync(context); + + return app; + } + + } +} \ No newline at end of file