Carubbi.ServiceLocator 2.0.0

dotnet add package Carubbi.ServiceLocator --version 2.0.0
                    
NuGet\Install-Package Carubbi.ServiceLocator -Version 2.0.0
                    
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="Carubbi.ServiceLocator" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Carubbi.ServiceLocator" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Carubbi.ServiceLocator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Carubbi.ServiceLocator --version 2.0.0
                    
#r "nuget: Carubbi.ServiceLocator, 2.0.0"
                    
#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.
#:package Carubbi.ServiceLocator@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Carubbi.ServiceLocator&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Carubbi.ServiceLocator&version=2.0.0
                    
Install as a Cake Tool

Carubbi.ServiceLocator

NuGet CI License: MIT

A simple helper that implements the Service Locator pattern, resolving concrete implementations for interfaces or well-known keys through Microsoft.Extensions.Configuration.

Features

  • Resolve interfaces to concrete types configured in any IConfiguration source (JSON, environment variables, in-memory, etc.) without a compile-time reference to the implementing project.
  • Resolve by friendly type name (including closed generics such as "IRepository[Customer]") or by arbitrary configuration key.
  • Constructor injection of parameters through reflection.
  • Singleton resolution through a public static GetInstance() factory method.
  • Plugin discovery: scan a directory for assemblies exposing classes that implement both IPlugin and a contract T.
  • Strict error handling: missing sections, missing keys and unloadable types throw descriptive exceptions instead of failing silently.

Installation

dotnet add package Carubbi.ServiceLocator

Requires .NET 10.0 or later.

Usage

Given an appsettings.json:

{
  "Implementations": {
    "IMessageService": "MyApp.Services.EmailMessageService, MyApp",
    "IRepository[int]": "MyApp.Data.IntRepository, MyApp"
  },
  "AppSettings": {
    "ConnectionString": "Server=.;Database=MyDb;Trusted_Connection=True;"
  }
}

Resolve implementations:

using Microsoft.Extensions.Configuration;
using Carubbi.ServiceLocator;

var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();

var resolver = new ImplementationResolver(configuration);

// By interface type name
IMessageService service = resolver.Resolve<IMessageService>();

// By explicit key with constructor parameters
var repository = resolver.Resolve<IRepository<int>>("IRepository[int]");

// Singleton via a public static GetInstance() factory method
var singleton = resolver.ResolveSingleton<IMessageService>();

Read key/value settings from a section:

var settings = new AppSettings(configuration, "AppSettings");
string connectionString = settings["ConnectionString"];

Discover plugins:

List<IGreeter> plugins = PluginLocator.GetPlugins<IGreeter>("path/to/plugins");

Note: type names must be resolvable by Type.GetType. Prefer assembly-qualified names (Namespace.Class, AssemblyName) and make sure the implementing assembly is available to the application.

Building and testing locally

Prerequisites:

dotnet build -c Release
dotnet test --solution Carubbi.ServiceLocator.sln

The unit tests run entirely in memory; no Docker or external infrastructure is required.

Releases

Releases are published to nuget.org automatically by the publish workflow whenever a tag matching v* is pushed:

git tag v2.0.0
git push origin v2.0.0

License

Distributed under the MIT License.

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

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Carubbi.ServiceLocator:

Package Downloads
Carubbi.Mainframe

Wrapper de Emulador de Terminal Mainframe Microfocus Rumba

Carubbi.Mailer.Interfaces

Contracts and dependency-injection helpers for sending and receiving email through pluggable providers such as SMTP/POP3, Exchange Web Services or Outlook interop.

Carubbi.CaptchaBreaker

Wrapper do Tesseract e do Captcha Breaker para quebra de captchas

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 146 8/26/2026
1.1.1 1,393 9/13/2018
1.1.0 1,090 9/13/2018
1.0.0 3,571 8/20/2018