Skip to content

Commit

Permalink
Merge pull request #3 from thomaslevesque/add-documentation
Browse files Browse the repository at this point in the history
Add documentation
  • Loading branch information
thomaslevesque authored Sep 23, 2018
2 parents 5ece8b5 + 12bd9db commit 90d2bae
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<PropertyGroup>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\AspNetCore.AsyncInitialization.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@
// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Provides extension methods to register async initializers.
/// </summary>
public static class AsyncInitializationServiceCollectionExtensions
{
/// <summary>
/// Registers necessary services for async initialization support.
/// </summary>
/// <param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> to add the service to.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddAsyncInitialization(this IServiceCollection services)
{
services.TryAddTransient<AsyncInitializer>();
return services;
}

/// <summary>
/// Adds an async initializer of the specified type.
/// </summary>
/// <typeparam name="TInitializer">The type of the async initializer to add.</typeparam>
/// <param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> to add the service to.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddAsyncInitializer<TInitializer>(this IServiceCollection services)
where TInitializer : class, IAsyncInitializer
{
Expand All @@ -22,6 +36,13 @@ public static IServiceCollection AddAsyncInitializer<TInitializer>(this IService
.AddTransient<IAsyncInitializer, TInitializer>();
}

/// <summary>
/// Adds the specified async initializer instance.
/// </summary>
/// <typeparam name="TInitializer">The type of the async initializer to add.</typeparam>
/// <param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> to add the service to.</param>
/// <param name="initializer">The service initializer</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddAsyncInitializer<TInitializer>(this IServiceCollection services, TInitializer initializer)
where TInitializer : class, IAsyncInitializer
{
Expand All @@ -30,13 +51,25 @@ public static IServiceCollection AddAsyncInitializer<TInitializer>(this IService
.AddSingleton<IAsyncInitializer>(initializer);
}

/// <summary>
/// Adds an async initializer with a factory specified in <paramref name="implementationFactory" />.
/// </summary>
/// <param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> to add the service to.</param>
/// <param name="implementationFactory">The factory that creates the async initializer.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddAsyncInitializer(this IServiceCollection services, Func<IServiceProvider, IAsyncInitializer> implementationFactory)
{
return services
.AddAsyncInitialization()
.AddTransient(implementationFactory);
}

/// <summary>
/// Adds an async initializer whose implementation is the specified delegate.
/// </summary>
/// <param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> to add the service to.</param>
/// <param name="initializer">The delegate that performs async initialization.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddAsyncInitializer(this IServiceCollection services, Func<Task> initializer)
{
return services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
// ReSharper disable once CheckNamespace
namespace Microsoft.AspNetCore.Hosting
{
/// <summary>
/// Provides extension methods to perform async initialization of an application.
/// </summary>
public static class AsyncInitializationWebHostExtensions
{
/// <summary>
/// Initializes the application, by calling all registered async initializers.
/// </summary>
/// <param name="host">The web host.</param>
/// <returns>A task that represents the initialization completion.</returns>
public static async Task InitAsync(this IWebHost host)
{
using (var scope = host.Services.CreateScope())
Expand Down
7 changes: 7 additions & 0 deletions src/AspNetCore.AsyncInitialization/IAsyncInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

namespace AspNetCore.AsyncInitialization
{
/// <summary>
/// Represents a type that performs async initialization.
/// </summary>
public interface IAsyncInitializer
{
/// <summary>
/// Performs async initialization.
/// </summary>
/// <returns>A task that represents the initialization completion.</returns>
Task InitializeAsync();
}
}

0 comments on commit 90d2bae

Please sign in to comment.