Documentation pass
All checks were successful
Nuget Pkg Build / build (push) Successful in 22s

This commit is contained in:
Samuele Lorefice
2025-09-21 20:48:41 +02:00
parent bf46d235af
commit e2cc807f70
5 changed files with 64 additions and 6 deletions

View File

@@ -1,5 +1,8 @@
namespace Syrette;
/// <summary>
/// Container for managing service registrations and resolutions.
/// </summary>
public class ServiceContainer {
private readonly List<ServiceDescriptor> descriptors = new();
private readonly Dictionary<Type, object> singletons = new();
@@ -13,6 +16,11 @@ public class ServiceContainer {
descriptors.Where(d => d.ServiceType == typeof(TServices))
.Select(d => d.ImplementationType).ToList();
/// <summary>
/// Registers a singleton service with its implementation.
/// </summary>
/// <typeparam name="TInterface">Interface the service is implementing</typeparam>
/// <typeparam name="TImplementation">Implementation type of the service</typeparam>
public ServiceContainer AddSingleton<TInterface, TImplementation>()
where TImplementation : class, TInterface {
descriptors.Add(new ServiceDescriptor {
@@ -25,6 +33,11 @@ public class ServiceContainer {
return this;
}
/// <summary>
/// Registers a transient service with its implementation.
/// </summary>
/// <typeparam name="TInterface">Interface the service is implementing</typeparam>
/// <typeparam name="TImplementation">Implementation type of the service</typeparam>
public ServiceContainer AddTransient<TInterface, TImplementation>()
where TImplementation : class, TInterface {
descriptors.Add(new ServiceDescriptor {
@@ -48,6 +61,11 @@ public class ServiceContainer {
return method.Invoke(this, null)!;
}
/// <summary>
/// Resolves and returns an instance of the requested service type.
/// </summary>
/// <typeparam name="TInterface">Interface type of the service being requested</typeparam>
/// <returns>Resolved service instance</returns>
public TInterface GetService<TInterface>() {
var descriptor = descriptors.FirstOrDefault(d => d.ServiceType == typeof(TInterface));

View File

@@ -1,8 +1,27 @@
namespace Syrette;
public class ServiceDescriptor {
/// <summary>
/// Describes a service for dependency injection, including its type, implementation, lifetime, and required dependencies.
/// </summary>
public class ServiceDescriptor
{
/// <summary>
/// Gets or sets the type of the service to be provided.
/// </summary>
public required Type ServiceType { get; set; }
/// <summary>
/// Gets or sets the concrete type that implements the service.
/// </summary>
public required Type ImplementationType { get; set; }
/// <summary>
/// Gets or sets the lifetime of the service (e.g., Singleton or Transient).
/// </summary>
public required ServiceLifetime Lifetime { get; set; }
/// <summary>
/// Gets or sets the list of types required by the implementation (dependencies).
/// </summary>
public List<Type> RequiredTypes { get; set; } = new();
}

View File

@@ -1,6 +1,15 @@
namespace Syrette;
/// <summary>
/// Defines the lifetime of a service in dependency injection.
/// </summary>
public enum ServiceLifetime {
/// <summary>
/// Defines a singleton service, which is created once and shared throughout the application's lifetime.
/// </summary>
Lifetime,
/// <summary>
/// Defines a transient service, which is created anew each time it is requested.
/// </summary>
Transient
}

View File

@@ -1,22 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Content Include="..\README.md">
<Link>README.md</Link>
<PackagePath>./</PackagePath>
</Content>
</ItemGroup>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.1-alpha</Version>
<Version>0.0.1.1-alpha</Version>
<Title>Syrette </Title>
<Authors>Lorefice Samuele</Authors>
<Description>Syrette is a minimalistic dependency injection library for C#. It aims to provide a simple and efficient way to achieve dependency injections in your applications without the overhead of larger frameworks.</Description>
<Copyright>2025 Lorefice Samuele</Copyright>
<PackageProjectUrl>https://git.r3d.codes/REDCODE/Syrette</PackageProjectUrl>
<PackageLicenseUrl>https://git.r3d.codes/REDCODE/Syrette/src/branch/master/LICENSE</PackageLicenseUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://git.r3d.codes/REDCODE/Syrette</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>DI, Dependency Injection</PackageTags>
<PackageTags>DI Dependency Injection</PackageTags>
<Company>Samuele Lorefice</Company>
<Deterministic>true</Deterministic>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<DocumentationFile>bin\Release\Syrette.xml</DocumentationFile>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String></wpf:ResourceDictionary>