Franz.Common.DependencyInjection
1.2.64
dotnet add package Franz.Common.DependencyInjection --version 1.2.64
NuGet\Install-Package Franz.Common.DependencyInjection -Version 1.2.64
<PackageReference Include="Franz.Common.DependencyInjection" Version="1.2.64" />
paket add Franz.Common.DependencyInjection --version 1.2.64
#r "nuget: Franz.Common.DependencyInjection, 1.2.64"
// Install Franz.Common.DependencyInjection as a Cake Addin #addin nuget:?package=Franz.Common.DependencyInjection&version=1.2.64 // Install Franz.Common.DependencyInjection as a Cake Tool #tool nuget:?package=Franz.Common.DependencyInjection&version=1.2.64
Franz.Common.DependencyInjection
A core library within the Franz Framework, designed to simplify and enhance the usage of dependency injection in .NET applications. This package provides utilities and extensions for efficient registration of services, managing lifetimes, and ensuring clean dependency resolution.
Features
1. Service Registration
- Scoped Dependencies:
- Automatically registers services implementing
IScopedDependency
with scoped lifetimes.
- Automatically registers services implementing
- Singleton Dependencies:
- Registers services implementing
ISingletonDependency
with singleton lifetimes.
- Registers services implementing
- Reflection-Based Registration:
- Automatically registers services based on custom reflection rules using
ITypeSourceSelectorExtensions
.
- Automatically registers services based on custom reflection rules using
2. Custom Strategies
- RegistrationStrategySkipExistingPair:
- Prevents duplicate service registrations, ensuring efficient dependency management.
3. Modular Integration
- Advanced Assembly Filtering:
- Filters assemblies using
FromCompanyApplicationDependenciesWithPredicate
for targeted registration.
- Filters assemblies using
- Flexible Service Types:
- Supports scoped, singleton, and transient registrations with various interfaces and class hierarchies.
Version Information
- Current Version:
1.2.64
- Part of the private Franz Framework ecosystem.
Dependencies
This package relies on:
- Microsoft.Extensions.DependencyInjection.Abstractions: Provides the core interfaces for dependency injection.
- Scrutor (4.2.2): Enables advanced scanning and automatic service registration.
- Franz.Common: Supplies core utilities for the framework.
- Franz.Common.Reflection: Adds reflection utilities for enhanced DI support.
Installation
From Private Azure Feed
Since this package is hosted privately, configure your NuGet client:
dotnet nuget add source "https://your-private-feed-url" \
--name "AzurePrivateFeed" \
--username "YourAzureUsername" \
--password "YourAzurePassword" \
--store-password-in-clear-text
Install the package:
dotnet add package Franz.Common.DependencyInjection --Version 1.2.64
Usage
1. Core Service Registration
Use the ServiceCollectionExtensions
to register common dependencies based on their interfaces and lifetimes:
Register Scoped Dependencies
Automatically register all classes implementing IScopedDependency
:
using Franz.Common.DependencyInjection.Extensions;
services.AddScopedDependencies();
Register Singleton Dependencies
Automatically register all classes implementing ISingletonDependency
:
using Franz.Common.DependencyInjection.Extensions;
services.AddSingletonDependencies();
Add Dependencies with Custom Assembly Filtering
Use a custom predicate to filter assemblies:
services.AddDependencies(assembly => assembly.GetName().Name.Contains("MyApp"));
2. Advanced Registration Patterns
Prevent Duplicate Registrations
Avoid redundant registrations using RegistrationStrategySkipExistingPair
:
using Franz.Common.DependencyInjection.Extensions;
services.AddWithStrategy<ILogger, Logger>(new RegistrationStrategySkipExistingPair());
Reflection-Based Registration
Automatically register services based on reflection:
services.Scan(scan => scan
.FromCompanyApplicationDependenciesWithPredicate(assembly => assembly.GetName().Name.StartsWith("MyCompany"))
.AddClasses(classes => classes.AssignableTo<IService>())
.AsImplementedInterfaces()
.WithScopedLifetime());
Custom Registration for Self and Matching Interfaces
Register services with custom rules:
services.AddSelfScoped<IOrderService>();
services.AddMatchingInterfaceScoped<IOrderService>();
services.AddImplementedInterfaceSingleton<IOrderService>();
3. Custom Extension Points
Add No-Duplicate Services
Ensure no duplicate services are added:
services.AddNoDuplicateScoped<IOrderService, OrderService>();
services.AddNoDuplicateSingleton<ILogger, Logger>();
services.AddNoDuplicateTransient<IService, ServiceImplementation>();
Add Inherited Class Registration
Register classes inheriting from a specific base type:
services.AddInheritedClassSingleton<MyBaseType>();
Integration with Franz Framework
The Franz.Common.DependencyInjection package integrates seamlessly with:
- Franz.Common: Provides foundational utilities.
- Franz.Common.Reflection: Enables advanced assembly and type filtering for DI registration.
Contributing
This package is part of a private framework. Contributions are limited to the internal development team. If you are authorized to contribute:
- Clone the repository. @ https://github.com/bestacio89/Franz.Common/
- Create a feature branch.
- Submit a pull request for review.
License
This library is licensed under the MIT License. See the LICENSE
file for more details.
Changelog
Version 1.2.64
- Upgrade version to .net 9
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net9.0
- Franz.Common (>= 1.2.64)
- Franz.Common.Reflection (>= 1.2.64)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.1)
- Scrutor (>= 6.0.1)
NuGet packages (13)
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.Messaging
Shared utility library for the Franz Framework. |
|
Franz.Common.EntityFramework
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.