yangxiaodong 7 лет назад
Родитель
Сommit
e136a05663
1 измененных файлов: 39 добавлений и 0 удалений
  1. +39
    -0
      src/Cap.Consistency/Microsoft.AspNetCore.Builder/BuilderExtensions.cs

+ 39
- 0
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
{
/// <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;
}

}
}

Загрузка…
Отмена
Сохранить