AddLib 2.0.5

dotnet add package AddLib --version 2.0.5
NuGet\Install-Package AddLib -Version 2.0.5
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="AddLib" Version="2.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AddLib --version 2.0.5
#r "nuget: AddLib, 2.0.5"
#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 AddLib as a Cake Addin
#addin nuget:?package=AddLib&version=2.0.5

// Install AddLib as a Cake Tool
#tool nuget:?package=AddLib&version=2.0.5

AddLib Nuget

Make internal great again!

Ever been annoyed that your application's entry point, Program.cs, must know about the whole dependency graph of every project in your solution to be able to configure the DI container?

Ever been annoyed that you can't mark a class or interface as internal because it makes them difficult to use via Dependency Injection?

AddLib can help you 🎉

AddLib provides a simple convention for encapsulating the internal types and functionality of class libraries.

Installation

dotnet add package AddLib

AddLib has a two external references to the lightweight Microsoft.Extensions.DependencyInjection.Abstractions and Microsoft.Extensions.Configuration.Abstractions packages, which will also be installed implicitly.

How to use

In your class library project, add a class that implements AddLib.ILibrary:

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace MySolution.Domain;

public class Library : AddLib.ILibrary
{
    public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
    {
        var connectionString = configuration.GetConnectionString("Default");

        services.AddTransient<IDatabaseContext>(x => new DatabaseContext(connectionString));
        services.AddTransient<IInternalDomainUtility, InternalDomainUtility>();
        services.AddTransient<IUserDomainService, UserDomainService>();
    }
}

In your application entry point, e.g. Program.cs, register the Library by pointing to the type:

services.AddLibrary<MySolution.Domain.Library>(configuration);

Or let AddLib scan assemblies for the ILibrary implementations:

// Scans the given assembly
services.AddLibrary(typeof(MySolution.Domain.IUserDomainService).Assembly, configuration);

Making internal visible to tests

You might ask: "Don't I still need to make all the classes and interfaces public so I can reference them in test projects?"

Not necessarily. You can use the InternalsVisibleTo attribute.

Either in your Project.csproj or Directory.Build.props:

<ItemGroup>
  <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
    <_Parameter1>MySolution.UnitTests</_Parameter1>
  </AssemblyAttribute>
</ItemGroup>

Or as code, placed anywhere in your library project:

[assembly: InternalsVisibleTo("MySolution.UnitTests")]
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.5 201 4/23/2023
1.0.3 264 2/4/2023
1.0.1 326 11/12/2022
0.1.16 320 11/12/2022
0.1.15 312 11/12/2022
0.1.14-alpha 120 11/12/2022
0.1.12-alpha 113 11/12/2022
0.1.8-alpha 104 11/5/2022
0.1.7-alpha 134 4/27/2022
0.1.6-alpha 137 4/27/2022
0.1.5-alpha 135 4/27/2022
0.1.4-alpha 138 4/27/2022