GraniteStateUsersGroups.RetCons
1.0.0
See the version list below for details.
dotnet add package GraniteStateUsersGroups.RetCons --version 1.0.0
NuGet\Install-Package GraniteStateUsersGroups.RetCons -Version 1.0.0
<PackageReference Include="GraniteStateUsersGroups.RetCons" Version="1.0.0" />
<PackageVersion Include="GraniteStateUsersGroups.RetCons" Version="1.0.0" />
<PackageReference Include="GraniteStateUsersGroups.RetCons" />
paket add GraniteStateUsersGroups.RetCons --version 1.0.0
#r "nuget: GraniteStateUsersGroups.RetCons, 1.0.0"
#:package GraniteStateUsersGroups.RetCons@1.0.0
#addin nuget:?package=GraniteStateUsersGroups.RetCons&version=1.0.0
#tool nuget:?package=GraniteStateUsersGroups.RetCons&version=1.0.0
RetCon: Retroactive Continuity for .NET
RetCon is a powerful .NET library designed to simplify and enhance dependency injection by allowing developers to retroactively define and manage service implementations. Inspired by the concept of retroactive continuity in storytelling, RetCon enables dynamic and flexible service registration using attributes.
Features
- Attribute-Based Service Registration: Use attributes to define and manage service implementations for interfaces.
- Priority-Based Selection: Control which implementation is chosen based on priority and conditions.
- Environment-Specific Implementations: Register services tailored to specific environments.
- Configuration-Driven Implementations: Dynamically register services based on configuration settings.
- Extensible and Modular: Easily extend the library to meet your specific needs.
- Kubernetes-Friendly Composition: Complement Kubernetes-based platforms with "module-lithic" services as an alternative to microservices.
Why RetCon?
RetCon empowers developers to:
- Leverage SOLID Principles: Decouple dependencies from the core application, enabling better maintainability and scalability.
- Compose Applications Dynamically: Use .NET reflection to discover and configure new implementations at startup without modifying the core application.
- Simplify Modular Design: Build modular applications that can dynamically adapt to new requirements or configurations.
This makes RetCon an excellent choice for applications that require flexibility, modularity, and dynamic composition. Use of Aspire.NET, Kubernetes, and RetCons all complement each other well without interfering with each other.
Getting Started
Installation
Add the RetCon library to your project by referencing the GraniteStateUsersGroups.RetCons
package. You can also include the GraniteStateUsersGroups.RetCons.Web
package for web-specific functionality. (NuGet packages yet to be produced.)
Usage
Define Your Interface and Implementation:
public interface IExampleService { void Execute(); } [RetCon.Default(typeof(IExampleService))] public class DefaultExampleService : IExampleService { public void Execute() => Console.WriteLine("Default Implementation"); }
Register and Initialize Services:
Use the following methods in your
Program.cs
file to discover and register service implementations and initialize activated services:var builder = WebApplication.CreateBuilder(args); // Discover and register services builder.AddRetConTargetServices(RetConDiscoveryLevel.RequireSignedAssemblies); var app = builder.Build(); // Initialize activated services app.UseRetConTargetServices(); app.Run();
AddRetConTargetServices
: Discovers and registers service implementations dynamically based on the RetCon attributes.UseRetConTargetServices
: Initializes the activated services after the application has been built.
Use
ISelfConfig
andISelfConfigAfterBuild
Interfaces:RetCon calls methods in these interfaces on subclasses of the actively selected implementation classes. Here’s how to use them:
Singular Subclass Implementing Both Interfaces:
public class MyService : ISelfConfig, ISelfConfigAfterBuild { public void Configure(WebApplicationBuilder builder, RetCon.RetConBaseAttribute attribute, IConfiguration configuration, ILogger logger) { logger.LogInformation("Configuring MyService with attribute {Attribute}", attribute); builder.Services.AddSingleton<IMyService, MyServiceImplementation>(); } public void PostBuildConfig(IApplicationBuilder app, RetCon.RetConBaseAttribute attribute, IConfiguration? configuration, ILogger logger) { logger.LogInformation("Post-build configuration for MyService with attribute {Attribute}", attribute); app.UseMiddleware<MyServiceMiddleware>(); } }
Configuration Subclass Contained Within the Service Class:
public class MyService { public class MyServiceConfig : ISelfConfig { public void Configure(WebApplicationBuilder builder, RetCon.RetConBaseAttribute attribute, IConfiguration configuration, ILogger logger) { logger.LogInformation("Configuring MyService with attribute {Attribute}", attribute); builder.Services.AddSingleton<IMyService, MyServiceImplementation>(); } } public class MyServicePostConfig : ISelfConfigAfterBuild { public void PostBuildConfig(IApplicationBuilder app, RetCon.RetConBaseAttribute attribute, IConfiguration? configuration, ILogger logger) { logger.LogInformation("Post-build configuration for MyService with attribute {Attribute}", attribute); app.UseMiddleware<MyServiceMiddleware>(); } } }
These examples illustrate how to use
ISelfConfig
andISelfConfigAfterBuild
to inject custom logic during the application’s configuration and post-build phases.
Example Projects
This repository includes sample projects demonstrating how to use RetCon attributes in real-world scenarios. Explore the samples to see how RetCon can simplify your dependency injection setup.
Documentation
Comprehensive documentation is planned but not yet available. A wiki will be created to host detailed guides, API references, and advanced usage examples.
To-Do
The following tasks are still pending:
- Comprehensive documentation needs to be written.
- Unit tests need to be implemented.
- A continuous integration pipeline needs to be built.
- A contribution guide needs to be written.
- NuGet packages for
GraniteStateUsersGroups.RetCons
andGraniteStateUsersGroups.RetCons.Web
need to be created and published. (These packages do not exist yet.) - A deployment pipeline needs to be built to publish releases to nuget.org.
- The implementation for
RetConDiscoveryLevel.RequireSignedAssemblies
needs to be added to the discovery process.
Contributing
We welcome contributions from the community! To contribute:
- Fork the repository.
- Create a feature branch.
- Commit your changes.
- Submit a pull request.
Please review our contribution guidelines (to be written) before submitting.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
RetCon is developed and maintained by the Granite State Users Groups. Special thanks to all contributors and the open-source community for their support.
Start redefining your dependency injection story with RetCon today!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. net9.0 was computed. 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. net10.0 was computed. 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. |
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Hosting (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- System.Text.Encodings.Web (>= 4.5.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on GraniteStateUsersGroups.RetCons:
Package | Downloads |
---|---|
GraniteStateUsersGroups.RetCons.Web
RetCons Library adapter for ASP.NET 8. |
GitHub repositories
This package is not used by any popular GitHub repositories.