aspnetcore/src/Microsoft.AspNetCore.Diagno.../MigrationsEndPointExtension...

51 lines
2.3 KiB
C#

// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Builder
{
/// <summary>
/// <see cref="IApplicationBuilder"/> extension methods for the <see cref="MigrationsEndPointMiddleware"/>.
/// </summary>
public static class MigrationsEndPointExtensions
{
/// <summary>
/// Processes requests to execute migrations operations. The middleware will listen for requests made to <see cref="MigrationsEndPointOptions.DefaultPath"/>.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param>
/// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns>
public static IApplicationBuilder UseMigrationsEndPoint(this IApplicationBuilder app)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
return app.UseMigrationsEndPoint(new MigrationsEndPointOptions());
}
/// <summary>
/// Processes requests to execute migrations operations. The middleware will listen for requests to the path configured in <paramref name="options"/>.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param>
/// <param name="options">An action to set the options for the middleware.</param>
/// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns>
public static IApplicationBuilder UseMigrationsEndPoint(this IApplicationBuilder app, MigrationsEndPointOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.UseMiddleware<MigrationsEndPointMiddleware>(Options.Create(options));
}
}
}