Fluentish.InjectableStatic.Generator
0.1.0
See the version list below for details.
dotnet add package Fluentish.InjectableStatic.Generator --version 0.1.0
NuGet\Install-Package Fluentish.InjectableStatic.Generator -Version 0.1.0
<PackageReference Include="Fluentish.InjectableStatic.Generator" Version="0.1.0" />
<PackageVersion Include="Fluentish.InjectableStatic.Generator" Version="0.1.0" />
<PackageReference Include="Fluentish.InjectableStatic.Generator" />
paket add Fluentish.InjectableStatic.Generator --version 0.1.0
#r "nuget: Fluentish.InjectableStatic.Generator, 0.1.0"
#addin nuget:?package=Fluentish.InjectableStatic.Generator&version=0.1.0
#tool nuget:?package=Fluentish.InjectableStatic.Generator&version=0.1.0
Fluentish.InjectableStatic.Generator
When upstream doesn't like inversion of control
Fluentish.InjectableStatic.Generator
is a source generator for C#. It allows you to generate interface and service classes that wrap static members of your target classes. By applying attributes, you can control which static classes and members become “injectable,” making it easier to work with otherwise rigid static code through a dependency injection container.
Features
Automatically generate wrapper classes and corresponding interfaces
Supported member types:
- Constants
- static Properties
- static Fields
- static Methods
Filter which members are included in generated code
Customize namespace prefix
Usage
Basic usage:
[assembly: Fluentish.InjectableStatic.Injectable(typeof(System.Console))]
Fluentish.Injectable.System.IConsole console = new Fluentish.Injectable.System.ConsoleService();
console.WriteLine("Hello, World!");
Will generate Fluentish.Injectable.System.IConsole
and Fluentish.Injectable.System.ConsoleService
, which contain all the static members.
Filtering members:
[assembly: Fluentish.InjectableStatic.Injectable(
typeof(System.Diagnostics.Debug),
FilterType.Exclude,
nameof(System.Diagnostics.Debug.Print)
)]
Will generate Fluentish.Injectable.System.Diagnostics.IDebug
and Fluentish.Injectable.System.Diagnostics.DebugService
without the Print
method.
[assembly: Fluentish.InjectableStatic.Injectable(
typeof(System.Diagnostics.Debug),
FilterType.Include,
nameof(System.Diagnostics.Debug.Write),
nameof(System.Diagnostics.Debug.WriteIf),
nameof(System.Diagnostics.Debug.WriteLine),
nameof(System.Diagnostics.Debug.WriteLineIf)
)]
Will generate Fluentish.Injectable.System.Diagnostics.IDebug
and Fluentish.Injectable.System.Diagnostics.DebugService
containing only the listed members.
Configuration
Custom namespace prefix:
To avoid name collisions, by default, generated classes are prefixed with Fluentish.Injectable.
, but you can change this behavior with the InjectableNamespacePrefixAttribute
.
To remove it:
[assembly: Fluentish.InjectableStatic.InjectableNamespacePrefixAttribute("")]
To place wrappers in a custom namespace:
[assembly: Fluentish.InjectableStatic.InjectableNamespacePrefixAttribute("My.Namespace")]
Remarks
Please note that this project is in its early stages of development and may require significant improvements. While it is functional, it may not be suitable for production use in its current state. Any feedback, suggestions, or contributions to improve the source generator are highly appreciated.
Contributing
Currently, I'm not accepting any code contributions because the project requires a major refactoring.
Support
If you have any questions, issues, or suggestions, please create a new issue on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for more information.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Fluentish.InjectableStatic.Generator:
Package | Downloads |
---|---|
Godot.DependencyInjection.Services
part of custom dependency injection for Godot game engine |
GitHub repositories
This package is not used by any popular GitHub repositories.