Marionette.Orange
0.0.6
dotnet add package Marionette.Orange --version 0.0.6
NuGet\Install-Package Marionette.Orange -Version 0.0.6
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="Marionette.Orange" Version="0.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Marionette.Orange" Version="0.0.6" />
<PackageReference Include="Marionette.Orange" />
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 Marionette.Orange --version 0.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Marionette.Orange, 0.0.6"
#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 Marionette.Orange@0.0.6
#: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=Marionette.Orange&version=0.0.6
#tool nuget:?package=Marionette.Orange&version=0.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Marionette.Orange
Marionette.Orange 是一个轻量级的基于属性的依赖注入辅助库,配套一个增量 Roslyn 源生成器,用于在构建时自动生成 IServiceCollection 的注册扩展方法。
特性
- 通过属性声明依赖注入语义(
[Injection]、[Injectable]、[InjectContext]) - 增量 Roslyn 源生成器:在编译期间生成类型安全的
IServiceCollection扩展(例如AddInjections) - 支持生命周期:Singleton、Transient、Scoped(以及作为 HostedService 的注册)
- 支持按 Key 的多实现注册
- 生成器诊断:在分析/生成阶段产生日志和诊断信息,方便排查
- 带有示例项目:
src/Marionette.Orange.SourceGenerators.Sample
快速开始
- 安装nuget包
dotnet add package Marionette.Orange
- 在期望被注入的接口上使用
[Injectable]标记作为注入契约。
[Injectable]
public interface IFoo;
- 在实现类上使用
[Injection]指定所实现的接口与生命周期;可选地指定 Key 以及接口类型
[Injection(InjectAs.Singleton)]
public class Foo1 : IFoo;
[Injection(InjectAs.Scope, typeof(IOther), Key="Foo2")]
public class Foo2 : IOther;
- 在某个对于
IServiceCollection的拓展方法上使用[InjectContext]
note:该方法和拓展类必须是分布方法
public static partial class SeviceCollectionExtension
{
[InjectContext]
public static partial IServiceCollection AddMarionetteOrangeService(this IServiceCollection);
}
- 在构建
ServiceCollection的地方调用生成的方法(比如Program.cs)
services.
...
.AddMarionetteOrangeService()
...
更多详细示例请查看:src/Marionette.Orange.SourceGenerators.Sample
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial package metadata update.