SyringeExtensions
NexusLabs.Needlr.Injection¶
NexusLabs.Needlr.Injection¶
SyringeExtensions Class¶
Core extension methods for configuring ConfiguredSyringe instances.
Inheritance System.Object 🡒 SyringeExtensions
Remarks¶
This class contains the core configuration methods that work with any implementation.
All methods operate on ConfiguredSyringe, which is created by calling
one of the strategy methods on Syringe:
- new Syringe().UsingSourceGen() - for AOT-compatible source-generated components
- new Syringe().UsingReflection() - for runtime reflection-based components
- new Syringe().UsingAutoConfiguration() - for automatic fallback
Methods¶
SyringeExtensions.AddDecorator<TService,TDecorator>(this ConfiguredSyringe) Method¶
Configures the syringe to add a decorator for the specified service type. This is a convenience method that adds a post-plugin registration callback to decorate the service. The decorator will preserve the original service's lifetime. Works with both interfaces and class types.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe AddDecorator<TService,TDecorator>(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe)
where TDecorator : class, TService;
Type parameters¶
TService
The service type (interface or class) to decorate.
TDecorator
The decorator type that implements TService.
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.BuildServiceProvider(this ConfiguredSyringe) Method¶
Builds a service provider with default configuration.
public static System.IServiceProvider BuildServiceProvider(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to build from.
Returns¶
System.IServiceProvider
The configured System.IServiceProvider.
SyringeExtensions.OrderAssemblies(this ConfiguredSyringe, AssemblyOrderBuilder) Method¶
Configures assembly ordering using a pre-built order builder.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe OrderAssemblies(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, NexusLabs.Needlr.Injection.AssemblyOrdering.AssemblyOrderBuilder orderBuilder);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
orderBuilder AssemblyOrderBuilder
The pre-configured order builder.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
Example¶
new Syringe()
.UsingSourceGen()
.OrderAssemblies(AssemblyOrder.LibTestEntry())
.BuildServiceProvider();
SyringeExtensions.OrderAssemblies(this ConfiguredSyringe, Action<AssemblyOrderBuilder>) Method¶
Configures assembly ordering using expression-based rules. Assemblies are sorted into tiers based on the first matching rule. Unmatched assemblies are placed last.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe OrderAssemblies(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, System.Action<NexusLabs.Needlr.Injection.AssemblyOrdering.AssemblyOrderBuilder> configure);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
configure System.Action<AssemblyOrderBuilder>
Action to configure the ordering rules.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
Example¶
new Syringe()
.UsingReflection() // or .UsingSourceGen()
.OrderAssemblies(order => order
.By(a => a.Name.EndsWith(".Core"))
.ThenBy(a => a.Name.Contains("Services"))
.ThenBy(a => a.Name.Contains("Tests")))
.BuildServiceProvider();
SyringeExtensions.UseLibTestEntryOrdering(this ConfiguredSyringe) Method¶
Configures assembly ordering: libraries first, then executables, tests last.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UseLibTestEntryOrdering(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UseTestsLastOrdering(this ConfiguredSyringe) Method¶
Configures assembly ordering: non-test assemblies first, tests last.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UseTestsLastOrdering(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UsingAdditionalAssemblies(this ConfiguredSyringe, IReadOnlyList<Assembly>) Method¶
Configures the syringe to use additional assemblies.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingAdditionalAssemblies(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, System.Collections.Generic.IReadOnlyList<System.Reflection.Assembly> additionalAssemblies);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
additionalAssemblies System.Collections.Generic.IReadOnlyList<System.Reflection.Assembly>
The additional assemblies to include.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UsingAssemblyProvider(this ConfiguredSyringe, IAssemblyProvider) Method¶
Configures the syringe to use the specified assembly provider.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingAssemblyProvider(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, NexusLabs.Needlr.Injection.IAssemblyProvider assemblyProvider);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
assemblyProvider IAssemblyProvider
The assembly provider to use.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UsingPluginFactory(this ConfiguredSyringe, IPluginFactory) Method¶
Configures the syringe to use the specified plugin factory.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingPluginFactory(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, NexusLabs.Needlr.IPluginFactory pluginFactory);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
pluginFactory NexusLabs.Needlr.IPluginFactory
The plugin factory to use.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UsingPostPluginRegistrationCallback(this ConfiguredSyringe, Action<IServiceCollection>) Method¶
Configures the syringe to add a single post-plugin registration callback. This callback is executed after plugin registration but before the service provider is finalized.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingPostPluginRegistrationCallback(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> callback);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
callback System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection>
The callback to execute during service provider building.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UsingPostPluginRegistrationCallbacks(this ConfiguredSyringe, IReadOnlyList<Action<IServiceCollection>>) Method¶
Configures the syringe to use post-plugin registration callbacks. These callbacks are executed after plugin registration but before the service provider is finalized.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingPostPluginRegistrationCallbacks(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, System.Collections.Generic.IReadOnlyList<System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection>> callbacks);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
callbacks System.Collections.Generic.IReadOnlyList<System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection>>
The callbacks to execute during service provider building.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UsingPreRegistrationCallback(this ConfiguredSyringe, Action<IServiceCollection>) Method¶
Configures the syringe to add a single pre-registration callback. This callback is executed before auto-discovery registration, useful for open generics or base registrations.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingPreRegistrationCallback(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> callback);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
callback System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection>
The callback to execute before auto-discovery.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UsingPreRegistrationCallbacks(this ConfiguredSyringe, IReadOnlyList<Action<IServiceCollection>>) Method¶
Configures the syringe to use pre-registration callbacks. These callbacks are executed before auto-discovery registration, useful for open generics or base registrations.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingPreRegistrationCallbacks(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, System.Collections.Generic.IReadOnlyList<System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection>> callbacks);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
callbacks System.Collections.Generic.IReadOnlyList<System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection>>
The callbacks to execute before auto-discovery.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UsingServiceCollectionPopulator(this ConfiguredSyringe, Func<ITypeRegistrar,ITypeFilterer,IPluginFactory,IServiceCollectionPopulator>) Method¶
Configures the syringe to use the specified service collection populator factory.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingServiceCollectionPopulator(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, System.Func<NexusLabs.Needlr.Injection.ITypeRegistrar,NexusLabs.Needlr.Injection.ITypeFilterer,NexusLabs.Needlr.IPluginFactory,NexusLabs.Needlr.Injection.IServiceCollectionPopulator> factory);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
factory System.Func<ITypeRegistrar,ITypeFilterer,NexusLabs.Needlr.IPluginFactory,IServiceCollectionPopulator>
The factory function for creating service collection populators.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UsingServiceProviderBuilderFactory(this ConfiguredSyringe, Func<IServiceCollectionPopulator,IAssemblyProvider,IReadOnlyList<Assembly>,IServiceProviderBuilder>) Method¶
Configures the syringe to use the specified service provider builder factory.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingServiceProviderBuilderFactory(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, System.Func<NexusLabs.Needlr.Injection.IServiceCollectionPopulator,NexusLabs.Needlr.Injection.IAssemblyProvider,System.Collections.Generic.IReadOnlyList<System.Reflection.Assembly>,NexusLabs.Needlr.Injection.IServiceProviderBuilder> factory);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
factory System.Func<IServiceCollectionPopulator,IAssemblyProvider,System.Collections.Generic.IReadOnlyList<System.Reflection.Assembly>,IServiceProviderBuilder>
The factory function for creating service provider builders.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UsingTypeFilterer(this ConfiguredSyringe, ITypeFilterer) Method¶
Configures the syringe to use the specified type filterer.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingTypeFilterer(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, NexusLabs.Needlr.Injection.ITypeFilterer typeFilterer);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
typeFilterer ITypeFilterer
The type filterer to use.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.UsingTypeRegistrar(this ConfiguredSyringe, ITypeRegistrar) Method¶
Configures the syringe to use the specified type registrar.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe UsingTypeRegistrar(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, NexusLabs.Needlr.Injection.ITypeRegistrar typeRegistrar);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
typeRegistrar ITypeRegistrar
The type registrar to use.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
SyringeExtensions.WithVerification(this ConfiguredSyringe, VerificationOptions) Method¶
Configures verification options for the syringe. Verification runs automatically during BuildServiceProvider(IConfiguration).
public static NexusLabs.Needlr.Injection.ConfiguredSyringe WithVerification(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, NexusLabs.Needlr.VerificationOptions options);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
options NexusLabs.Needlr.VerificationOptions
The verification options to use.
Returns¶
ConfiguredSyringe
A new configured syringe instance.
Example¶
// Strict mode - throw on any issue
new Syringe()
.UsingSourceGen()
.WithVerification(VerificationOptions.Strict)
.BuildServiceProvider();
// Disable verification
new Syringe()
.UsingSourceGen()
.WithVerification(VerificationOptions.Disabled)
.BuildServiceProvider();
// Custom configuration
new Syringe()
.UsingSourceGen()
.WithVerification(new VerificationOptions
{
LifetimeMismatchBehavior = VerificationBehavior.Throw,
IssueReporter = issue => logger.LogWarning(issue.Message)
})
.BuildServiceProvider();
SyringeExtensions.WithVerification(this ConfiguredSyringe, Action<VerificationOptionsBuilder>) Method¶
Configures verification options using a builder action.
public static NexusLabs.Needlr.Injection.ConfiguredSyringe WithVerification(this NexusLabs.Needlr.Injection.ConfiguredSyringe syringe, System.Action<NexusLabs.Needlr.VerificationOptionsBuilder> configure);
Parameters¶
syringe ConfiguredSyringe
The configured syringe to update.
configure System.Action<NexusLabs.Needlr.VerificationOptionsBuilder>
An action to configure the verification options.
Returns¶
ConfiguredSyringe
A new configured syringe instance.