AddLib 2.0.5
dotnet add package AddLib --version 2.0.5
NuGet\Install-Package AddLib -Version 2.0.5
<PackageReference Include="AddLib" Version="2.0.5" />
paket add AddLib --version 2.0.5
#r "nuget: AddLib, 2.0.5"
// 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
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 | Versions 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. |
-
.NETStandard 2.0
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 | 235 | 4/23/2023 |
1.0.3 | 295 | 2/4/2023 |
1.0.1 | 352 | 11/12/2022 |
0.1.16 | 344 | 11/12/2022 |
0.1.15 | 335 | 11/12/2022 |
0.1.14-alpha | 150 | 11/12/2022 |
0.1.12-alpha | 135 | 11/12/2022 |
0.1.8-alpha | 130 | 11/5/2022 |
0.1.7-alpha | 155 | 4/27/2022 |
0.1.6-alpha | 164 | 4/27/2022 |
0.1.5-alpha | 157 | 4/27/2022 |
0.1.4-alpha | 159 | 4/27/2022 |