SharpServiceCollection 0.0.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package SharpServiceCollection --version 0.0.2
NuGet\Install-Package SharpServiceCollection -Version 0.0.2
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="SharpServiceCollection" Version="0.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SharpServiceCollection" Version="0.0.2" />
<PackageReference Include="SharpServiceCollection" />
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 SharpServiceCollection --version 0.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SharpServiceCollection, 0.0.2"
#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 SharpServiceCollection@0.0.2
#: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=SharpServiceCollection&version=0.0.2
#tool nuget:?package=SharpServiceCollection&version=0.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Installation
To install, run dotnet add package SharpServiceCollection or
from Nuget
Introduction
SharpServiceCollection is a lightweight C# library that wraps the `IServiceCollection interface to streamline
dependency injection through attribute-based assembly scanning.
Usage
SharpServiceCollectionscans an assembly to automatically register services in theIServiceCollectioncontainer.- Use the
AddServicesBySharpServiceCollectionextension method ofIServiceCollectionto perform assembly scanning. - By default, it will scan the executing assembly using
Assembly.GetCallingAssembly(), the method has an overload that accepts an assembly.
using SharpServiceCollection.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Default
builder.Services.AddServicesBySharpServiceCollection();
// Overload
builder.Services.AddServicesBySharpServiceCollection(typeof(Program).Assembly);
var app = builder.Build();
InstanceLifetimeis an Enum with the valuesSingletonScopedTransientIServiceCollectioncomes withAdd*andTryAdd*methods.SharpServiceCollectionoffers the same functionality.SharpServiceCollectionwill perform lexicographical sort on the class name to register dependency when duplicates occur. For example,FooBarBazwill be sorted asBarBazFoo, If three of them are resolved byIDemoInterface, NonTry*based attributes will register the last one, which isFoo,Try*based attributes will register the first one, which isBar- In general, it is better to use
Try*based attributes.
using SharpServiceCollection.Attributes;
using SharpServiceCollection.Enums;
[TryResolveBy<IScopedDemoService>(InstanceLifetime.Scoped)]
[ResolveBy<IScopedDemoService>(InstanceLifetime.Scoped)]
public class ScopedDemoType : IScopedDemoService, IKeyedScopedDemoService
{
}
[KeyedTryResolveBy<IKeyedScopedDemoService>(InstanceLifetime.Scoped, "keyed")]
[KeyedResolveBy<IKeyedScopedDemoService>(InstanceLifetime.Scoped, "keyed")]
public class ScopedDemoType : IScopedDemoService, IKeyedScopedDemoService
{
}
[TryResolveBySelf(InstanceLifetime.Scoped)]
[ResolveBySelf(InstanceLifetime.Scoped)]
public class ScopedDependency : IScopedDependency
{
}
[TryResolveByMatchingInterface(InstanceLifetime.Scoped)]
[ResolveByMatchingInterface(InstanceLifetime.Scoped)]
public class ScopedDependency : IScopedDependency
{
}
| 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 was computed. 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. net10.0 was computed. 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.
-
net8.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.