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
<PackageReference Include="RonSijm.Syringe" Version="0.1.1" />
paket add RonSijm.Syringe --version 0.1.1
#r "nuget: RonSijm.Syringe, 0.1.1"
// 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...
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 | 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 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. |
-
net8.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Configuration.Json (>= 8.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
-
net9.0
- Microsoft.Extensions.Configuration (>= 9.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.1)
- Microsoft.Extensions.Configuration.Json (>= 9.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.