Franz.Common.DependencyInjection
3.0.0
dotnet add package Franz.Common.DependencyInjection --version 3.0.0
NuGet\Install-Package Franz.Common.DependencyInjection -Version 3.0.0
<PackageReference Include="Franz.Common.DependencyInjection" Version="3.0.0" />
<PackageVersion Include="Franz.Common.DependencyInjection" Version="3.0.0" />
<PackageReference Include="Franz.Common.DependencyInjection" />
paket add Franz.Common.DependencyInjection --version 3.0.0
#r "nuget: Franz.Common.DependencyInjection, 3.0.0"
#:package Franz.Common.DependencyInjection@3.0.0
#addin nuget:?package=Franz.Common.DependencyInjection&version=3.0.0
#tool nuget:?package=Franz.Common.DependencyInjection&version=3.0.0
Franz.Common.DependencyInjection
Assembly scanning and explicit service-registration helpers built on Microsoft DI and Scrutor.
Overview
Assembly scanning and explicit service-registration helpers built on Microsoft DI and Scrutor.
Installation
dotnet add package Franz.Common.DependencyInjection
Marker-based registration
The package recognizes IScopedDependency and ISingletonDependency markers from Franz.Common. The marker interface itself does not register a service; invoke the corresponding extension and ensure the implementation assembly is included by the package's assembly selector.
using Franz.Common.DependencyInjection;
using Franz.Common.DependencyInjection.Extensions;
services.AddScopedDependencies();
services.AddSingletonDependencies();
AddDependencies() composes both marker scans. Each scan registers implemented interfaces other than the marker interface and uses RegistrationStrategySkipExistingPair.
Assembly selection
The scanning methods accept an optional Func<Assembly, bool> predicate. The underlying FromCompanyApplicationDependenciesWithPredicate selector determines the candidate assemblies; the predicate narrows that set.
services.AddDependencies(
assembly => assembly.GetName().Name?.StartsWith("Contoso.", StringComparison.Ordinal) == true);
Use explicit, stable assembly-selection rules. A broad scan can register infrastructure from test, tooling, or unrelated application assemblies.
Explicit scanning extensions
The package also exposes these Scrutor-backed helpers:
| Extension | Registration shape |
|---|---|
AddSelfScoped<TInterface> |
Matching implementations as themselves, scoped |
AddMatchingInterfaceScoped<TInterface> |
Matching interface, scoped |
AddImplementedInterfaceScoped<TInterface> |
All implemented interfaces, scoped |
AddImplementedInterfaceTransient<TInterface> |
All implemented interfaces, transient |
AddImplementedInterfaceSingleton<TInterface> |
All implemented interfaces, singleton |
AddImplementedInterfaceWithoutMarkerScoped<TInterface> |
Implemented interfaces excluding the marker type, scoped |
AddImplementedInterfaceWithoutMarkerSingleton<TInterface> |
Implemented interfaces excluding the marker type, singleton |
AddInheritedClassSingleton<TType> |
Register matching classes as TType, singleton |
These methods scan assemblies selected by FromCompanyApplicationDependenciesWithPredicate; they are not global scans of every loaded assembly.
Native AOT and trimming
The Scrutor assembly-scanning extensions (AddDependencies, AddScopedDependencies, AddSelfScoped, and the other scan-based helpers) are explicitly marked with RequiresUnreferencedCode. They discover arbitrary assemblies and implementation types at runtime, so they are intended for JIT applications and are not part of the Native AOT contract. Native AOT callers should not suppress those warnings.
Use explicit generic registrations instead:
services.AddNoDuplicateSingleton<IClock, SystemClock>();
services.AddNoDuplicateScoped<IOrderRepository, OrderRepository>();
The generic implementation-type overloads preserve public constructors through DynamicallyAccessedMembers annotations. Type-based overloads carry the same constructor-preservation requirement on their Type parameter. Factory and instance registrations remain explicit and do not require assembly discovery.
The package's Native AOT smoke suite publishes and executes a consumer that uses explicit generic registration. It deliberately does not call assembly-scanning APIs.
Duplicate-registration semantics
RegistrationStrategySkipExistingPair compares both ServiceType and ImplementationType. An existing matching pair is retained. If the same pair is already registered with a different lifetime, registration throws rather than silently preserving an inconsistent lifetime.
The package also exposes AddNoDuplicateService and typed AddNoDuplicateSingleton, AddNoDuplicateScoped, and AddNoDuplicateTransient overloads for implementation types, instances, and factories. These helpers use the same pair-based strategy. They do not deduplicate registrations merely because the service type matches when the implementation differs.
Lifetime design
- Scoped services must not be captured by singleton services.
- Singleton implementations must be thread-safe and must not retain request-specific state.
- Transient registrations create a new instance per resolution, subject to the consuming container's normal semantics.
Namespace
All extension methods are in Franz.Common.DependencyInjection.Extensions. The custom strategy is Franz.Common.DependencyInjection.RegistrationStrategySkipExistingPair.
License
MIT. See LICENSE.
| Product | Versions 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. |
-
net10.0
- Franz.Common (>= 3.0.0)
- Franz.Common.Reflection (>= 3.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.14)
- Scrutor (>= 7.0.0)
NuGet packages (16)
Showing the top 5 NuGet packages that depend on Franz.Common.DependencyInjection:
| Package | Downloads |
|---|---|
|
Franz.Common.Business
Shared utility library for the Franz Framework. |
|
|
Franz.Common.Headers
Shared utility library for the Franz Framework. |
|
|
Franz.Common.Serialization
Shared utility library for the Franz Framework. |
|
|
Franz.Common.Messaging
Shared utility library for the Franz Framework. |
|
|
Franz.Common.Hosting
Shared utility library for the Franz Framework. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 241 | 11/10/2026 |
| 2.3.4 | 797 | 11/1/2026 |
| 2.3.3 | 685 | 10/28/2026 |
| 2.3.2 | 485 | 10/27/2026 |
| 2.3.1 | 546 | 10/26/2026 |
| 2.3.0 | 715 | 7/21/2026 |
| 2.2.19 | 545 | 7/19/2026 |
| 2.2.18 | 548 | 7/19/2026 |
| 2.2.17 | 1,129 | 7/12/2026 |
| 2.2.16 | 546 | 7/2/2026 |
| 2.2.15 | 550 | 6/29/2026 |
| 2.2.14 | 555 | 6/29/2026 |
| 2.2.13 | 564 | 6/29/2026 |
| 2.2.12 | 541 | 6/28/2026 |
| 2.2.11 | 551 | 6/28/2026 |
| 2.2.10 | 544 | 6/28/2026 |
| 2.2.9 | 544 | 6/28/2026 |
| 2.2.8 | 677 | 6/28/2026 |
| 2.2.7 | 550 | 6/7/2026 |
| 2.2.6 | 549 | 6/6/2026 |