using System;
using Microsoft.AspNetCore.NodeServices;
namespace Microsoft.Extensions.DependencyInjection
{
///
/// Extension methods for setting up NodeServices in an .
///
public static class NodeServicesServiceCollectionExtensions
{
///
/// Adds NodeServices support to the .
///
/// The .
public static void AddNodeServices(this IServiceCollection serviceCollection)
=> AddNodeServices(serviceCollection, _ => {});
///
/// Adds NodeServices support to the .
///
/// The .
/// A callback that will be invoked to populate the .
public static void AddNodeServices(this IServiceCollection serviceCollection, Action setupAction)
{
if (setupAction == null)
{
throw new ArgumentNullException(nameof (setupAction));
}
serviceCollection.AddSingleton(typeof(INodeServices), serviceProvider =>
{
// First we let NodeServicesOptions take its defaults from the IServiceProvider,
// then we let the developer override those options
var options = new NodeServicesOptions(serviceProvider);
setupAction(options);
return NodeServicesFactory.CreateNodeServices(options);
});
}
}
}