Skip to content

Commit

Permalink
Re-factored context logging by addin an ILoggingContext interface and…
Browse files Browse the repository at this point in the history
… generalizing the Log extension methods. (#11)
  • Loading branch information
mgernand authored May 10, 2022
1 parent 2234719 commit 77b398e
Show file tree
Hide file tree
Showing 21 changed files with 207 additions and 548 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Fluxera.Extensions.DependencyInjection.Abstractions" Version="6.0.28" />
<InternalsVisibleTo Include="Fluxera.Extensions.Hosting" />
<InternalsVisibleTo Include="Fluxera.Extensions.Hosting.AspNetCore" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Fluxera.Extensions.DependencyInjection.Abstractions" Version="6.0.29" />
<PackageReference Include="Fluxera.Guards" Version="6.0.22" />
<PackageReference Include="GitVersion.MsBuild" Version="5.10.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

/// <summary>
/// A contract for a context type that is available during the application
/// initialization of modules. One service context instance is passed
/// down the module list.
/// </summary>
[PublicAPI]
public interface IApplicationInitializationContext
public interface IApplicationInitializationContext : ILoggingContext<IServiceProvider>
{
/// <summary>
/// Gets the service provider.
Expand All @@ -28,10 +27,5 @@ public interface IApplicationInitializationContext
/// Gets the environment the host runs under.
/// </summary>
IHostEnvironment Environment { get; }

/// <summary>
/// Gets a logger.
/// </summary>
ILogger Logger { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

/// <summary>
/// A contract for a context type that is available during the application
/// shutdown of modules. One service context instance is passed down the module list.
/// </summary>
[PublicAPI]
public interface IApplicationShutdownContext
public interface IApplicationShutdownContext : ILoggingContext<IServiceProvider>
{
/// <summary>
/// Gets the service provider.
Expand All @@ -27,10 +26,5 @@ public interface IApplicationShutdownContext
/// Gets the environment the host run under.
/// </summary>
IHostEnvironment Environment { get; }

/// <summary>
/// Gets a logger.
/// </summary>
ILogger Logger { get; set; }
}
}
30 changes: 30 additions & 0 deletions src/Fluxera.Extensions.Hosting.Abstractions/ILoggingContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Fluxera.Extensions.Hosting
{
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

/// <summary>
/// A contract for a context that provides logging capabilities.
/// </summary>
[PublicAPI]
public interface ILoggingContext<out T> : ILoggingContext
where T : class
{
/// <summary>
/// Gets the context data, f.e. IServiceCollection.
/// </summary>
internal T LogContextData { get; }
}

/// <summary>
/// A contract for a context that provides logging capabilities.
/// </summary>
[PublicAPI]
public interface ILoggingContext
{
/// <summary>
/// Gets a logger.
/// </summary>
ILogger Logger { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

/// <summary>
/// A contract for a context type that is available during the service
/// configuration of modules. One service context instance is passed
/// down the module list.
/// </summary>
[PublicAPI]
public interface IServiceConfigurationContext
public interface IServiceConfigurationContext : ILoggingContext<IServiceCollection>
{
/// <summary>
/// Gets the service collection.
Expand All @@ -30,11 +29,6 @@ public interface IServiceConfigurationContext
/// </summary>
IHostEnvironment Environment { get; }

/// <summary>
/// Gets a logger.
/// </summary>
ILogger Logger { get; }

/// <summary>
/// Gets additional items that can be passed down the module service configuration pipeline.
/// This items are shared between modules during the service configuration phase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

/// <summary>
/// A contract for a context type that is given to the plugin module configuration.
/// </summary>
[PublicAPI]
public interface IPluginConfigurationContext
public interface IPluginConfigurationContext : ILoggingContext<IPluginSourceList>
{
/// <summary>
/// The list of plugin sources. One may add additional sources to configure
Expand All @@ -26,10 +25,5 @@ public interface IPluginConfigurationContext
/// Gets the environment the application runs under.
/// </summary>
IHostEnvironment Environment { get; }

/// <summary>
/// Gets a logger.
/// </summary>
ILogger Logger { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public interface IPluginSourceList : ICollection<IPluginSource>
/// all available <see cref="IPluginSource" /> instances.
/// </summary>
/// <returns></returns>
IEnumerable<Assembly> GetAllAssemblies();
internal IEnumerable<Assembly> GetAllAssemblies();

/// <summary>
/// Gets all <see cref="IModule" /> types from all available
/// <see cref="IPluginSource" /> instances including their dependencies.
/// </summary>
/// <returns></returns>
IEnumerable<Type> GetAllModules();
internal IEnumerable<Type> GetAllModules();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public WebApplicationInitializationContext(IApplicationBuilder applicationBuilde
public IHostEnvironment Environment { get; }

/// <inheritdoc />
public ILogger Logger { get; set; }
public ILogger Logger { get; }

/// <inheritdoc />
IServiceProvider ILoggingContext<IServiceProvider>.LogContextData => this.ServiceProvider;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public ApplicationInitializationContext(IServiceProvider serviceProvider)
public IHostEnvironment Environment { get; }

/// <inheritdoc />
public ILogger Logger { get; set; }
public ILogger Logger { get; }

/// <inheritdoc />
IServiceProvider ILoggingContext<IServiceProvider>.LogContextData => this.ServiceProvider;
}
}

This file was deleted.

5 changes: 4 additions & 1 deletion src/Fluxera.Extensions.Hosting/ApplicationShutdownContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public ApplicationShutdownContext(IServiceProvider serviceProvider)
public IHostEnvironment Environment { get; }

/// <inheritdoc />
public ILogger Logger { get; set; }
public ILogger Logger { get; }

/// <inheritdoc />
IServiceProvider ILoggingContext<IServiceProvider>.LogContextData => this.ServiceProvider;
}
}

This file was deleted.

Loading

0 comments on commit 77b398e

Please sign in to comment.