58 lines
2.2 KiB
C#
58 lines
2.2 KiB
C#
// Copyright (c) .NET Foundation. 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.Elm;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
namespace Microsoft.Extensions.DependencyInjection
|
|
{
|
|
/// <summary>
|
|
/// Extension methods for setting up Elm services in an <see cref="IServiceCollection" />.
|
|
/// </summary>
|
|
public static class ElmServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds error logging middleware services to the specified <see cref="IServiceCollection" />.
|
|
/// </summary>
|
|
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
|
|
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
|
|
public static IServiceCollection AddElm(this IServiceCollection services)
|
|
{
|
|
if (services == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(services));
|
|
}
|
|
|
|
services.AddOptions();
|
|
services.TryAddSingleton<ElmStore>();
|
|
services.TryAddSingleton<ElmLoggerProvider>();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds error logging middleware services to the specified <see cref="IServiceCollection" />.
|
|
/// </summary>
|
|
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
|
|
/// <param name="setupAction">An <see cref="Action{ElmOptions}"/> to configure the provided <see cref="ElmOptions"/>.</param>
|
|
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
|
|
public static IServiceCollection AddElm(this IServiceCollection services, Action<ElmOptions> setupAction)
|
|
{
|
|
if (services == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(services));
|
|
}
|
|
|
|
if (setupAction == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(setupAction));
|
|
}
|
|
|
|
services.AddElm();
|
|
services.Configure(setupAction);
|
|
|
|
return services;
|
|
}
|
|
}
|
|
} |