J4JSoftware.DependencyInjection 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package J4JSoftware.DependencyInjection --version 2.0.1                
NuGet\Install-Package J4JSoftware.DependencyInjection -Version 2.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="J4JSoftware.DependencyInjection" Version="2.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add J4JSoftware.DependencyInjection --version 2.0.1                
#r "nuget: J4JSoftware.DependencyInjection, 2.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install J4JSoftware.DependencyInjection as a Cake Addin
#addin nuget:?package=J4JSoftware.DependencyInjection&version=2.0.1

// Install J4JSoftware.DependencyInjection as a Cake Tool
#tool nuget:?package=J4JSoftware.DependencyInjection&version=2.0.1                

Dependency Injection

There are breaking changes in this release. Please re-review the github documentation.

Provides a customized IHostBuilder-based system for producing an IHost instance which contain a number of useful services. These include:

  • logging (via J4JLogger)
  • application and user configuration file management
  • simple data protection (i.e., encryption and decryption of strings, via Microsoft.AspNetCore.DataProtection)
  • command line parsing (via J4JCommandLine)
  • dependency injection (via Autofac)

This assembly targets Net5 and has nullability enabled.

This example is derived from my GeoProcessor console app. However, it's been simplified to illustrate certain concepts more clearly and therefore will not work "as written".

internal class Program
{
    internal static IHost? Host { get; private set; }

    private static readonly CancellationToken _cancellationToken = new();
    private static IJ4JLogger? _buildLogger;

    private static async Task Main( string[] args )
    {
        var hostConfig = new J4JHostConfiguration()
            .ApplicationName( "GeoProcessor" )
            .Publisher( "J4JSoftware" )
            .OperatingSystem( OSNames.Windows )
            .AddApplicationConfigurationFile("appConfig.json")
            .AddUserConfigurationFile("userConfig.json")
            .AddConfigurationInitializers(SetupConfiguration)
            .LoggerInitializer( SetupLogging )
            .FilePathTrimmer(FilePathTrimmer)
            .OptionsInitializer( SetupOptions )
            .AddDependencyInjectionInitializers( SetupDependencyInjection )
            .AddServicesInitializers( SetupServices );

        _buildLogger = hostConfig.Logger;
        var builder = hostConfig.CreateHostBuilder();
        Host = builder.Build();

        await Host!.RunAsync( _cancellationToken );
    }
}

This example Main program shows the basic outline of how to use J4JConfigurationHost. You create an instance, call various extension methods on it, check to see if all the basic requirements are satisfied, create the builder by calling CreateHostBuilder(), make sure the builder got built, and then call Build() on the builder.

Please note, however, that we store the build-time logger, contained in J4JConfigurationHost's Logger property, in a field variable. This is done so we can reference it in some of the configuration actions we've defined below. That lets the configuration actions report on issues and problems when they execute when the IHost instance gets built.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on J4JSoftware.DependencyInjection:

Package Downloads
J4JSoftware.GeoProcessor

a library for processing GPX, KML and KMZ files, and snapping GPS tracks to roadways

J4JSoftware.WPFUtilities

utilities for console applications

J4JSoftware.GeoProcessorApp

a console application for processing GPX, KML and KMZ files, and snapping GPS tracks to roadways

J4JSoftware.GeoProcessorWPF

a WPF application for processing GPX, KML and KMZ files, and snapping GPS tracks to roadways

J4JSoftware.DeusWinApp

provides J4JDeusEx support for Windows Apps (WinUI 3)

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.6.0 208 5/2/2023
2.5.1 221 4/11/2023
2.5.0 200 4/4/2023
2.4.0 310 1/15/2023
2.3.3 303 1/8/2023
2.3.2 304 1/8/2023
2.3.1 297 1/1/2023
2.3.0 296 12/27/2022
2.2.0 445 2/28/2022
2.1.1 573 11/21/2021
2.1.0 308 11/12/2021
2.0.1 934 9/29/2021
2.0.0 1,028 9/28/2021
1.1.0 1,021 2/3/2021
1.0.0 443 1/21/2021
0.8.0 377 1/9/2021

added nuget readme