RonSijm.Syringe 0.1.1

Prefix Reserved
dotnet add package RonSijm.Syringe --version 0.1.1                
NuGet\Install-Package RonSijm.Syringe -Version 0.1.1                
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="RonSijm.Syringe" Version="0.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RonSijm.Syringe --version 0.1.1                
#r "nuget: RonSijm.Syringe, 0.1.1"                
#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.
// Install RonSijm.Syringe as a Cake Addin
#addin nuget:?package=RonSijm.Syringe&version=0.1.1

// Install RonSijm.Syringe as a Cake Tool
#tool nuget:?package=RonSijm.Syringe&version=0.1.1                

RonSijm.Syringe

A library for to make it easier to do dependency injection.

Get it? A Syringe is used to inject things. Yes jokes are better when you have to explain them...

codecov

More documentation to come 😃

Default ServiceCollection Extensions:

<a id='snippet-CodeExample-DefaultServiceCollection-WireByType'></a>

var serviceCollection = new ServiceCollection();
serviceCollection.WireImplicit(typeof(Class));
var serviceProvider = serviceCollection.BuildServiceProvider();

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/Registration/DefaultServiceCollection/InitiationMethods/TestWireImplicit_Type.cs#L10-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-DefaultServiceCollection-WireByType' title='Start of snippet'>anchor</a></sup>

<a id='snippet-CodeExample-DefaultServiceCollection-WireByTypeGeneric'></a>

var serviceCollection = new ServiceCollection();
serviceCollection.WireImplicit<Class>();
var serviceProvider = serviceCollection.BuildServiceProvider();

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/Registration/DefaultServiceCollection/InitiationMethods/TestWireImplicit_GenericType.cs#L10-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-DefaultServiceCollection-WireByTypeGeneric' title='Start of snippet'>anchor</a></sup>

<a id='snippet-CodeExample-DefaultServiceCollection-WireByAssembly'></a>

var serviceCollection = new ServiceCollection();
var assembly = typeof(Class).Assembly;
serviceCollection.WireImplicit(assembly, ServiceLifetime.Transient, []);
var serviceProvider = serviceCollection.BuildServiceProvider();

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/Registration/DefaultServiceCollection/InitiationMethods/TestWireImplicit_Assembly.cs#L10-L15' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-DefaultServiceCollection-WireByAssembly' title='Start of snippet'>anchor</a></sup>

Scoped: (default)

<a id='snippet-CodeExample-DefaultScope'></a>

return typeof(ClassWithGuid).WireImplicit().BuildServiceProvider();

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/Registration/Attributes/LifetimeTests/LifetimeTests_Scoped.cs#L10-L12' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-DefaultScope' title='Start of snippet'>anchor</a></sup>

Transient:

<a id='snippet-CodeExample-TransientScope'></a>

return typeof(ClassWithGuid).WireImplicit().WithLifetime(ServiceLifetime.Transient).BuildServiceProvider();

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/Registration/Attributes/LifetimeTests/LifetimeTests_Transient.cs#L10-L12' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-TransientScope' title='Start of snippet'>anchor</a></sup>

Singleton:

<a id='snippet-CodeExample-SingletonScope'></a>

return typeof(ClassWithGuid).WireImplicit().WithLifetime(ServiceLifetime.Singleton).BuildServiceProvider();

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/Registration/Attributes/LifetimeTests/LifetimeTests_Singleton.cs#L10-L12' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-SingletonScope' title='Start of snippet'>anchor</a></sup>

<a id='snippet-CodeExample-Parameters-registerAsTypesOnly'></a>

var serviceCollection = new ServiceCollection();
serviceCollection.WireImplicit<Class>(registerAsTypesOnly: [typeof(ClassWithInterface)]);
var serviceProvider = serviceCollection.BuildServiceProvider();

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/Registration/DefaultServiceCollection/Parameters/TestWireImplicit_RegisterAsTypesOnly_ClassWithInterface.cs#L11-L15' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-Parameters-registerAsTypesOnly' title='Start of snippet'>anchor</a></sup>

<a id='snippet-CodeExample-Parameters-registerBothTypeAndInterfaces'></a>

var serviceCollection = new ServiceCollection();
serviceCollection.WireImplicit<Class>(registerBothTypeAndInterfaces: [typeof(ClassWithInterface)]);
var serviceProvider = serviceCollection.BuildServiceProvider();

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/Registration/DefaultServiceCollection/Parameters/TestWireImplicit_RegisterBothTypeAndInterfaces_ClassWithInterface.cs#L10-L14' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-Parameters-registerBothTypeAndInterfaces' title='Start of snippet'>anchor</a></sup>

Extension Methods

By doing a WireImplicit - The extension will return a SyringeServiceCollectionAndRegistration object. This is an object that keeps track of the last registion that you've made, allowing you to append extra configuration to that specific registration:

<a id='snippet-CodeExample-DontRegisterTypesExtension'></a>

var serviceCollection = new SyringeServiceCollection();
serviceCollection.WireImplicit<Class>().DontRegisterTypes(typeof(Class));

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/CustomCollection/Parameters/TestWireImplicit_DontRegisterAsTypes_Class.cs#L11-L14' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-DontRegisterTypesExtension' title='Start of snippet'>anchor</a></sup>

<a id='snippet-CodeExample-DontRegisterTypesWithInterfaces'></a>

var serviceCollection = new SyringeServiceCollection();
serviceCollection.WireImplicit<Class>().DontRegisterTypesWithInterfaces([typeof(InterfaceFor_ClassWithInterface)]);

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/CustomCollection/Parameters/TestWireImplicit_DontRegisterTypesWithInterface_InterfaceFor_ClassWithInterface.cs#L11-L14' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-DontRegisterTypesWithInterfaces' title='Start of snippet'>anchor</a></sup>

<a id='snippet-CodeExample-RegisterAsTypesOnly'></a>

var serviceCollection = new SyringeServiceCollection();
serviceCollection.WireImplicit<Class>().RegisterAsTypesOnly([typeof(ClassWithInterface)]);

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/CustomCollection/Parameters/TestWireImplicit_RegisterAsTypesOnly_ClassWithInterface.cs#L11-L14' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-RegisterAsTypesOnly' title='Start of snippet'>anchor</a></sup>

<a id='snippet-CodeExample-RegisterBothTypeAndInterfaces'></a>

var serviceCollection = new SyringeServiceCollection();
serviceCollection.WireImplicit<Class>().RegisterBothTypeAndInterfaces([typeof(ClassWithInterface)]);

<sup><a href='/src/Tests/RonSijm.Syringe.Tests/Features/Tests/CustomCollection/Parameters/TestWireImplicit_RegisterBothTypeAndInterfaces_ClassWithInterface.cs#L10-L13' title='Snippet source file'>snippet source</a> | <a href='#snippet-CodeExample-RegisterBothTypeAndInterfaces' title='Start of snippet'>anchor</a></sup>

Product 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.1 80 2/4/2025
0.0.3 184 12/10/2024
0.0.2 86 12/10/2024
0.0.1 92 12/10/2024